I need help finding two logic errors and one execution error in this short python program?

num = input("Enter a number or 0 to quit:")


total = 0 



while num != 0: 

    total = total + num 


    num = float(input("Enter a number or 0 to quit: ") 

    print("Total is :", total)


When I look at it I see that the second num input needs to be at the end which is one logic error and then both num input need to be floated but wouldn't that be one logic error and two execution errors?


Float is not supposed to be on the second num input I posted wrong sorry.

3 Answers

  • 1 month ago
    Best Answer

    Actually , float() should be on *both* inputs. The input() function always returns an input line as a string.

    But you're missing a closing parenthesis in the input inside the loop.  Should be:

        num = float(input("Enter a number or 0 to quit: ")) # both times

    Then, at the end, your final print() call should be unindented, so it's not part of the loop.  (If you want to show a running total, print that after adding to the total, but *before* asking for another number.

  • Anonymous
    1 month ago

    total = 0

    while True:

    ... num = input( "Enter a number or 0 to quit:" )

    ... if "0" == num:

    ... ... break

    ... else:

    ... ... total += float(num)

    ... ... print( "Total is" , total)

  • VP
    Lv 7
    1 month ago

    a. You need to tell us what the program IS SUPPOSED to do.

    b. Maybe you should just try running it and see what happens.

    c. What does the 2nd "num =" line look like?

Still have questions? Get your answers by asking now.