Home > OS >  Same output repeating in loop
Same output repeating in loop

Time:06-20

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

CodePudding user response:

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)
  • Related