Advertisement
Guest User

code.py

a guest
May 3rd, 2017
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.51 KB | None | 0 0
  1. import string
  2.  
  3. def start():
  4.     print("Welcome to a Netflix ripoff\nWould you like to register or login?\nType register or login\n")
  5.     selection = input("Would you like to login, register or exit?: ").title()
  6.    
  7.     if selection == "Register":
  8.         register()
  9.     elif selection == "Login":
  10.         login()
  11.     elif selection == "Exit":
  12.         exit()
  13.  
  14.  
  15. def register():
  16.  
  17.     def has_uppercase(pw):
  18.         "Password must contain an uppercase letter"
  19.         return len(set(string.ascii_uppercase).intersection(pw)) > 0
  20.     def has_numeric(pw):
  21.         "Password must contain a digit"
  22.         return len(set(string.digits).intersection(pw)) > 0
  23.  
  24.     def test_password(pw, tests=[has_uppercase, has_numeric]):
  25.         for test in tests:
  26.             if not test(pw):
  27.                 print(test.__doc__)
  28.                 return False
  29.         return True
  30.  
  31.     def interestsel():
  32.         interests = input("What are your interests?(seperate with a space): \nSci-Fi,\nAdventure or\nAction\n").title()
  33.         if interests == "":
  34.             print("\nYour account has been created. Please login\n\n")
  35.             start()
  36.         else:
  37.             file = open("accounts.txt","a")
  38.             file.write(interests)
  39.             file.close()
  40.             print("\nYour account has been created. Please login\n\n")
  41.             start()          
  42.      
  43.    
  44.     def gendersel():
  45.         gender = input("What is your gender (Male or Female): ").title()
  46.         if gender == "Male":
  47.             file = open("accounts.txt","a")
  48.             file.write(gender)
  49.             file.close()
  50.            
  51.             interestsel()
  52.         elif gender == "Female":
  53.             file = open("accounts.txt","a")
  54.             file.write(gender)
  55.             file.close()
  56.            
  57.             interestsel()
  58.            
  59.         else:
  60.             print("\nInvalid gender. Please re-enter your gender: \n")
  61.             gendersel()
  62.  
  63.  
  64.  
  65.     def pwcheck():
  66.         pw = input("What would you like your password to be?: ")
  67.         if test_password(pw):
  68.             file = open("accounts.txt","a")
  69.             file.write(pw+",")
  70.             file.close()
  71.             gendersel()
  72.         else:
  73.             print("\nYour password needs atleast one capital letter and one number, please try again.\n")
  74.             pwcheck()
  75.  
  76.  
  77.  
  78.     def usernamecheck():
  79.         username = input("What would you like your username to be?: ")
  80.  
  81.         with open("accounts.txt","r+") as file:  
  82.             for line in file:
  83.                 line = line.split(",")
  84.                 if username == line[3]:
  85.                     print("\nThis username is already taken please try again.\n")
  86.                     usernamecheck()
  87.                 else:
  88.                     file = open("accounts.txt","a")
  89.                     file.write(username+",")
  90.                     file.close()
  91.                     pwcheck()
  92.             file.close()
  93.  
  94.     def firstinfo():
  95.         realname = input("What is your realname?: ")
  96.         dob = input("What is your date of birth?(DD/MM/YYYY): ")
  97.         address = input("What is your address?: ")
  98.  
  99.        
  100.         file = open("accounts.txt","a")
  101.         file.write("\n"+realname+","+dob+","+address+",")
  102.         file.close()
  103.  
  104.         usernamecheck()
  105.        
  106.     firstinfo()
  107.      
  108.        
  109. def login():
  110.     username = input("\nEnter your username: ")
  111.     password = input("Enter your password: ")
  112.     with open("accounts.txt","r+") as file:
  113.         for line in file:
  114.             line = line.split(",")
  115.             if username == line[3] and password == line[4]:
  116.                 homepage()
  117.             else:
  118.                 print("\n***********************************")
  119.                 print("Error. Your username or password is incorrect. Please try again.")
  120.                 print("***********************************\n")
  121.                 login()
  122.     file.close()
  123.  
  124.  
  125.  
  126. def watch():
  127.     print("Watching\n")
  128.     start()
  129.  
  130. def history():
  131.     print("History\n")
  132.     start()
  133.  
  134.  
  135. def homepage():
  136.     print("****************************")
  137.     print("---===Welcome to your homepage===---")
  138.     print("What would you like to do?: ")
  139.     print("To watch a program, type watch")
  140.     print("To view your watch history, type history")
  141.     print("To logout and exit, type quit")
  142.     print("****************************\n")
  143.     hpselect = input("\n").title()
  144.  
  145.     if hpselect == "Watch":
  146.         watch()
  147.     elif hpselect == "History":
  148.         history()
  149.     elif hpselect == "Quit":
  150.         exit()
  151.        
  152.  
  153. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement