Why doesn’t the result of input() match what I expect to get? [closed]

The user input is in variable name_choice, but you compare name to “Sam” (so the user input is never used).

And you are also comparing a string to a list, this will always be False

In [32]: name = ['Sam']

In [33]: 'Sam' == name
Out[33]: False

causing the program to always display “Your name isn’t Sam”, regardless of what the user entered.

if name_choice == 'Sam':
   print ("Your name is Sam")
else:
   print ("Your name isn't Sam")

is probably what you want to do

Leave a Comment