-1

I tried to input 1 in the object code but the else statement always executes even though my if statement is equal to 1 and evaluates to true:

intro = input("Welcome to Gazebo  (Press Enter to continue)")
print ("Choose your menu  (Type the number for the corresponding option)")
print ("1 - Starters ")
print ("2 - Main Menu ")
print ("3 - Sweets ")
print ("4 - Cold drinks ")
print ("5 - Juices ")
print ("6 - Ice Creams ")
menu = input("e ")
if menu == 1 :
    print ("Choose your menu  (Type the number for the corresponding option)")
    print ("1 - Starters ")
    print ("2 - Main Menu ")
    print ("3 - Sweets ")
    print ("4 - Cold drinks ")
    print ("5 - Juices ")
    print ("6 - Ice Creams ")
    Str1 = input("Enter the corresponding number for the desired dish")
else :
    print ("Bye")
P.P
  • 117,907
  • 20
  • 175
  • 238

1 Answers1

0

The comparison in this line:

if menu == 1 :

will always evaluate to false because you're not converting the input to a number before comparing, hence regardless of what you input the else statement will execute.

To fix this convert the input to a number using int, float but not eval (its usage is almost never required in daily-life usage, look up its dangers; provided this here only for information) and then comparisons should work as intended.

Ethicist
  • 791
  • 2
  • 7
  • 23