-5

When I run this code it always goes to the else. Even when I choose 1, 2, or 3. How can I achieve a proper if, elif else statement?

def main():
    name = input("What is your name?")
    print("Hello", name)
    choice = int
    choice = 0
    choice = input("Please choose a number from the following options: \n 1. Paper \n 2. Rock \n 3. Scissors")
    print (choice)

    if choice == 1:
        print ('You chose number 1')
    elif choice == 2:
        print ('You chose number 2')
    elif choice == 3:
        print ('You chose number 3')
    else:
        print ('Invalid Entry Mush')
    return

main()
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
David
  • 3
  • 1
  • 2
    Which programming language is this? – JSN Jul 21 '17 at 13:10
  • Please tag as Python. There are some unnecessary lines of code in your script, but the problem is the input is a string and not an integer. wrap the numbers in the conditions with quotes. – Yuval Ben-Arie Jul 21 '17 at 13:13

2 Answers2

1

input returns a string. You will need to cast it to an int so that your elif options that check for ints are triggered:

choice = int(input("Please choose a number from the following options: \n 1. Paper \n 2. Rock \n 3. Scissors"))

By the way the two lines before that one are unnecessary.

Cary Shindell
  • 1,336
  • 8
  • 25
0

Or you can put your if statements between quotes: ex: if choice == "1" print("nr 1") elif choice == "2" so on ..

ricristian
  • 466
  • 4
  • 17