Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check variable value through elif statement?

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")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

operator = int(operator)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading