1

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
5
  • 3
    Because you keep entering 0 as an input? So U is always 0, and the while loop continues - what happens if you enter something other than 0? (by the way, your question appears to be a Python 3 question, not a Python 2 one, please remove the tag or update your code if it is a Python 2 question) Commented Jun 19, 2022 at 23:06
  • Since you aren't using U in that loop, what's the point of entering it? Commented Jun 19, 2022 at 23:14
  • Hii @Grismar, how are you ?, I updated the premium or that I triggered something other than zero :) ,and removed the paython 2 tag Commented Jun 19, 2022 at 23:18
  • hii @TimRoberts, All very well?, it's just so the program doesn't keep repeating without my permission, so I can write down the data calmly Commented Jun 19, 2022 at 23:21
  • Hi @Priscilla I see you use the letter U only to end the loop. If you enter 0, the loop ends. If you have a certain number of loops, I recommend using a for loop. Commented Jun 19, 2022 at 23:29

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.