-1

After running the code if I type anything other than john or johnny, it still prints out JOHNNY!!! Why is this?

user_name = input('What is your name?')

if user_name.lower() == 'john' or 'johnny':
    print ('JOHNNY!!!')
elif user_name.lower() == 'bill' or 'billy':
    print ('BILLY!!!')
else:
    print ('Hello {0}'.format(user_name))
Zimm
  • 3
  • 1

2 Answers2

1

You need to correct all your conditions like the following way:

if user_name.lower() == 'john' or user_name.lower() =='johnny':

A good way to do is

if user_name.lower() in {'john' ,'johnny'}:
Md Johirul Islam
  • 5,042
  • 4
  • 23
  • 56
0

@JacobIRR has a better solution but you can also do what's posted below.

user_name = input('What is your name?')

if user_name.lower() == 'john' or user_name.lower() == 'johnny':
    print ('JOHNNY!!!')

elif user_name.lower() == 'bill' or user_name.lower() == 'billy':
    print ('BILLY!!!')

else:
    print ('Hello {0}'.format(user_name))
Michael Swartz
  • 858
  • 2
  • 15
  • 27