How to check variable value through elif statement?

Question:

I’m currently trying to make a quick calculator and can’t seem to get my Elif statements to read the variable value correctly. When run, the program just goes to the error statement. Not sure what I’m doing wrong.

print("Enter a number:")

number1 = input()

print("Enter a second number:")

number2 = input()

operator = input("Enter a number to 1)Multiply 2)Divide 3)Add 4)Subtract :   ")

int(operator)

if operator == 1:
  result = number1 * number2
  print(result)
elif operator == 2:
  result = number1 / number2
  print(result)
elif operator == 3:
  result = number1 + number2
  print(result)
elif operator == 4:
  result = number1 - number2
  print(result)
else:
  print("Enter a correct number")
Asked By: u32Luke

||

Answers:

You are not assigning the int(operator) to operator so change like this,

operator = int(operator)
Answered By: Rahul K P
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.