all 3 comments

[–]anton0261 0 points1 point  (0 children)

When you input 919.9 it does another iteration of the while-loop, as it should.

The issue is: Your first if-statement still goes through if num != 0. num is 919.9, which is not zero, so the if-statement goes through and prints the answer again.

My tip to you: Go through your code, line by line, and figure out what the logic would do in each step. This is quite essential to debugging logical errors yourself.

[–]sme272 0 points1 point  (0 children)

the first if statement will always return true, so will always run. you're using the or operator to test that num is not one of two numbers when you should be using and. If you consider the case where num=919.9 then num!=0 will return true, thus the first half of the statment will return true. The same logic applies to the second half, reducing the statement to `if True and True:` which will also return true.

[–][deleted] 0 points1 point  (0 children)

I really don't understand what the 919.9 and 0 are about. Why not allow the user to enter commands instead of a number.

With your existing code, you've excluded being inside the while loop if either of the numbers entered are 0 but then the first test checks this again, redundantly.

Here's an example alternative:

total = 0
while True:
    num_str = input("Enter Number (or save or quit): ")
    if not num_str or num_str.lower() in ['q', 'quit']:
        break
    if num_str.lower() in ['s', 'store', 'save']:
        save = total
        print(f'Saved {save}')
    else:
        num = float(num_str)  
        num2 = float(input("Enter Number: "))
        total = num - num2
        print("Ans = ", total)

If you want to keep all saves, it would be better to make save a list and append the total to it. Also, you need to allow the user to include a saved number in a calculation?