dimanche 3 mai 2020

Why does the 'else' statement execute even though the 'if' was true?

I can't work out why the output is evaluating to "?" instead of to int(3). Could someone please explain this? Running Python 3.8.

number1=3
number2=1
operator="*"
if operator =="+":
    answer=number1+number2
if operator =="-":
    answer=number1-number2
if operator =="*":
    answer=number1*number2
if operator =="/":
    answer=number1/number2
else:
    answer="?"
print(answer)

I tried the search function but could not find anything that resolved my issue. Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire