-1

I am having difficulty with this practice problem.

Implement a program that starts by asking the user to enter a login id (i.e., a string). The program then checks whether the id entered by the user is in the list ['joe', 'sue','hani', 'sophie'] of valid users. Depending on the outcome, an appropriate message should be printed. Regardless of the outcome, your function should print 'Done.'

Here is the code I wrote

login = input('enter login name')
if login == 'joe' or 'sue' or 'hani' or 'sophie':
    print('you are in!')   
else:
    print('User unknown')

print('Done.')

However no matter what I input my code always returns 'you are in!' and I don't know why.

Matthew
  • 777
  • 1
  • 9
  • 23
A.G
  • 31
  • 5

2 Answers2

1

Change if login == 'joe' or 'sue' or 'hani' or 'sophie':

to if login == 'joe' or login == 'sue' or login =='hani' or login =='sophie':

right now it is checking if login is equal to 'joe', or if 'sue' or 'hani' or 'sophie' are true which they always are because their sizes are not equal to 0

Nicky Mirfallah
  • 1,004
  • 4
  • 16
  • 38
0

Try this, it will give you more flexibility in case your the number of names gets bigger:

loginList = ['joe', 'sue', 'hani', 'sophie']
if login in loginList:
    print('you are in!')   
else:
    print('User unknown')
Armaiti
  • 766
  • 3
  • 11
  • This doesn't really address his main problem, which is misunderstanding how conditionals evaluate. You've only given him an alternative. He's likely to have the nearly exact same question in the future. – Carcigenicate Jan 26 '16 at 23:41