Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

Try this:

arr = []

while (i < num_of_guesses):
    y = int(input("enter y: "))
    arr.append(x*y)
    for m in arr:
        print(m)
    i += 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading