Why printing result = 0?

Question:

end = False
while end != True:
    f = float(input("Enter Number: "))
    oper = input("Enter operator: +, -, *, /, = : ")
    result = 0
    if oper == '+':
        a = f + f
        result += a
    elif oper == '-':
        a = f - f
        result += a
    elif oper == '*':
        a = f * f
        result += a
    elif oper == '/':
        a = f / f
        result += a
    elif oper or f == "=":
        print(result)
    else:
        end = True
        print("Something is Wrong")

I am trying to make calculator with while loop to ask until "end" equals to false, but i have problem when i enter numbers and then "=" its printing 0 and not result, pls somebody help i am begginer and sorry if my english isn’t good.

Asked By: Giorgi Maisuradze

||

Answers:

result = 0 is in your while loop. So it is evaluated every times.

Try this instead:

result = 0
while end != True:
   ...
Answered By: ErnestBidouille
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.