-2

I don't understand what's wrong with my code here. Can someone help me pls? I've been trying to solve it all morning.

question = input("Choose from 0 to 1 : ") 
mylist = ["Mark", "Jenny"] 
if question == 0: 
    print(mylist[0], "is your new friend") 
elif question == 1: 
    print(mylist[1], "is your new friend")
else:
    print("I said choose from 0 to 1")

1 Answers1

1

The problem is in the data types:

input() returns a string but in your, if statement you're comparing a string "0" to an integer 0. Because of that else is always executed.

Concert the input() into int() like shown below:

question = int(input("Choose from 0 to 1 : "))
mylist = ["Mark", "Jenny"] 
if question == 0: 
    print(mylist[0], "is your new friend") 
elif question == 1: 
    print(mylist[1], "is your new friend")
else:
    print("I said choose from 0 to 1")
Geom
  • 1,491
  • 1
  • 10
  • 23