Advertisement
Guest User

Untitled

a guest
May 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. # Define a Users tuple containing at least three strings (all must be unique)
  2. users = ('proview','brennan','yankees','jets')
  3.  
  4. # Define a Passwords tuple containing a password string for each user in the User tuple
  5. passwords = ('web','patrick','champs','football')
  6.  
  7. # Ask the user for a username
  8. username = raw_input('Please enter your username: ')
  9.  
  10. # Ask the user for a password
  11. code = raw_input('Please enter your password: ')
  12.  
  13. # If the provided username is in the Users tuple (check by using the in operator)
  14. if username in users:
  15.  
  16. # Make a copy of the Users tuple as a LIST
  17. L_users = list(users)
  18.  
  19. # Find the index that matches the username – use the index() method of lists
  20. place = users.index(username)
  21.  
  22. # If the string in the Passwords tuple (at the index located above) matches
  23. if code == passwords[place]:
  24.  
  25. # the user-provided password, confirm the match with a print statement
  26. print('Your username of "%s" and password of "%s" are correct, welcome!!\n' % (username,code))
  27.  
  28. # In either case, print out the Users tuple and the Passwords tuple
  29. print(users)
  30. print(passwords)
  31.  
  32. else:
  33. #otherwise, print a “doesn't match” message
  34. print('Your password "%s" does not match any password in our database' % (code))
  35.  
  36. # otherwise
  37. else:
  38. # Concatenate a string together with the username embedded in the string (see example)
  39. print('"%s" does not match any username in our database,' % (username)),
  40.  
  41. # Ask the user to enroll. Use the variable containing the concatenated string as prompt to raw_input()
  42. ask = raw_input('would you like to enroll?: ')
  43.  
  44. # If the user wants to enroll:
  45. if ask == 'y':
  46.  
  47. # convert the Users tuple into a list, append the username, then convert back to a tuple
  48. users = list(users)
  49. users.append(username)
  50. users = tuple(users)
  51.  
  52. # convert the Passwords tuple into a list, append the password, then convert back to a tuple
  53. passwords = list(passwords)
  54. passwords.append(code)
  55. passwords = tuple(passwords)
  56.  
  57. # In either case, print out the Users tuple and the Passwords tuple
  58. print(users)
  59. print(passwords)
  60.  
  61. #otherwise
  62. else:
  63. print('\nGoodbye!!!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement