'Print previous values

I am looking to print values that were obtained through a previous loop:

for example:

x=10
while i < num_of_guesses:
   y = int(input("enter y: ")
   print(x*y)
   i += 1

My goal is to print every value obtained again, so the output would look something like this

enter y: 1
10
enter y: 2
10
20
enter y: 1.5
10
20
15

The problem I'm having is figuring out a way to print the 10 and 20 (in this example) again. Any solution?



Solution 1:[1]

You can store the users inputs and append to a list, somethig like this:

x= 10
i = 0
values = []
while i < 10:
   y = int(input("enter y: "))
   values.append(y*x)
   print('\n'.join([str(v) for v in values]))
   i += 1

Output:

enter y: 1
10
enter y: 20
10
200
enter y: 2
10
200
20

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ezequiel Celona