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

Same output repeating in loop

Why does my program only show the line of code U=float(input( "Enter the value of the letter ‘U’ : " )) in the terminal?

    B=0
    A=0
    U=0

    while(U == 0):
     
         U=float(input( "Enter the value of the letter 'U' :" ))
     
         ent=[200,101,255,11]

         for i in ent:
         
             A = A + (i * ( 1 -(1/10**2)  ) / 255)  -1/(10**2)

             B = B + i

    print(B)

The output of the program in the terminal is this:

Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  9
4536

Process finished with exit code 0

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

>Solution :

it seems like you need to fix indentation on the "print(B)" line

By giving one more TAB you will be printing each time the user inputs something, and with one more TAB you will be printing for each value inside your array!

For example, by having print() inside the for loop, the variable B will be shown 4 times (due to the ent variable) each time the user inserts a number:

    B=0
    A=0
    U=0

    while(U == 0):
     
         U=float(input( "Enter the value of the letter 'U' :" ))
     
         ent=[200,101,255,11]

         for i in ent:
         
             A = A + (i * ( 1 -(1/10**2)  ) / 255)  -1/(10**2)

             B = B + i

             print(B)
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