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.
Answers:
result = 0
is in your while loop. So it is evaluated every times.
Try this instead:
result = 0
while end != True:
...
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.
result = 0
is in your while loop. So it is evaluated every times.
Try this instead:
result = 0
while end != True:
...