0

Here is my code, why does it keep returning the else value even though I am inputting a valid operation?

num1 = float(input("Choose a number: "))
op = input("Choose an operation: ")
num2 = float(input("Choose a second number: "))


if op == "+":
    print(num1 + num2)
elif op == "-":
    print(num1 - num2)
elif op == "*":
    print(num1 * num2)
elif op == "/":
    print(num1 / num2)
else:
    print("Invalid Operator")
Joshzk
  • 1
  • The use of `input` might be the problem, as indicated [here](https://stackoverflow.com/questions/19054661/if-input-equals-string-do-something-python-2-7). – Chrimle Dec 25 '21 at 23:59
  • Does this answer your question? [if input equals string, do something... python 2.7](https://stackoverflow.com/questions/19054661/if-input-equals-string-do-something-python-2-7) – Chrimle Dec 26 '21 at 00:00

1 Answers1

0

your program seems correct and it produces correct output. Probably, there could be something wrong with your input. Here is an example of input and output by your program.

Choose a number: 5
Choose an operation: +
Choose a second number: 3
8.0
bvsh
  • 64
  • 6