197k views
2 votes
HELP PYTHON PROGRAMMING

Write a function named is_valid that gets two strings arguments, username and password.

The function will return True if the username and password are valid in the system, otherwise False.

Our system contains only two valid usernames - "admin" and "user".

The valid password for username "user" is "qweasd".

For username "admin" any password is valid!

1 Answer

6 votes

usernames = ['admin', 'user']

def is_valid():

username = input('Username')

password = input('Password')

if username in usernames:

if username == 'user':

if password == 'qweasd':

print('True')

else:

print('False')

elif username == 'admin':

print('True')

else:

print('False')

else:

print('False')

is_valid()

Should work. If you need to tweak it, it is written intuitively.

User Marsbear
by
8.2k points