Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define a Users tuple containing at least three strings (all must be unique)
- users = ('proview','brennan','yankees','jets')
- # Define a Passwords tuple containing a password string for each user in the User tuple
- passwords = ('web','patrick','champs','football')
- # Ask the user for a username
- username = raw_input('Please enter your username: ')
- # Ask the user for a password
- code = raw_input('Please enter your password: ')
- # If the provided username is in the Users tuple (check by using the in operator)
- if username in users:
- # Make a copy of the Users tuple as a LIST
- L_users = list(users)
- # Find the index that matches the username – use the index() method of lists
- place = users.index(username)
- # If the string in the Passwords tuple (at the index located above) matches
- if code == passwords[place]:
- # the user-provided password, confirm the match with a print statement
- print('Your username of "%s" and password of "%s" are correct, welcome!!\n' % (username,code))
- # In either case, print out the Users tuple and the Passwords tuple
- print(users)
- print(passwords)
- else:
- #otherwise, print a “doesn't match” message
- print('Your password "%s" does not match any password in our database' % (code))
- # otherwise
- else:
- # Concatenate a string together with the username embedded in the string (see example)
- print('"%s" does not match any username in our database,' % (username)),
- # Ask the user to enroll. Use the variable containing the concatenated string as prompt to raw_input()
- ask = raw_input('would you like to enroll?: ')
- # If the user wants to enroll:
- if ask == 'y':
- # convert the Users tuple into a list, append the username, then convert back to a tuple
- users = list(users)
- users.append(username)
- users = tuple(users)
- # convert the Passwords tuple into a list, append the password, then convert back to a tuple
- passwords = list(passwords)
- passwords.append(code)
- passwords = tuple(passwords)
- # In either case, print out the Users tuple and the Passwords tuple
- print(users)
- print(passwords)
- #otherwise
- else:
- print('\nGoodbye!!!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement