Advertisement
Guest User

Menu Python CA

a guest
Oct 4th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. import csv
  2.  
  3. def menu():
  4.     choice = input("Welcome to the Quiz Menu, \n 1. Login \n 2. Register \n 3. Quit \n")
  5.     if choice == '1':
  6.         login()
  7.     elif choice == '2':
  8.         register()
  9.     else:
  10.         quit()
  11.  
  12.  
  13. def login():
  14.     with open('users.csv') as csvfile:
  15.             reader = csv.DictReader(csvfile)
  16.             database = []
  17.             for row in reader:
  18.                 database.append(dict(username=row['username'],
  19.                                      password=row['password'],
  20.                                      admin=row['admin']))
  21.     loggedin = False
  22.     while not loggedin:
  23.         Username = input('Fill in your username: ')
  24.         Password = input('Fill in your password: ')
  25.         for row in database:
  26.             Username_File = row['username']
  27.             Password_File = row['password']
  28.             Admin_File = row['admin']
  29.             if (Username_File == Username and
  30.                 Password_File == Password and
  31.                  Admin_File == '0'):
  32.                 loggedin = True
  33.                 print('Succesfully logged in as a Student.')
  34.             elif (Username_File == Username and
  35.                   Password_File == Password and
  36.                     Admin_File == '1'):
  37.                 loggedin = True
  38.                 print('Succesfully logged in as an Admin.')
  39.         if loggedin is not True:
  40.             print ('Failed to sign in, wrong username or password.')
  41.  
  42.  
  43. def register():
  44.     with open('users.csv') as csvfile:
  45.         reader = csv.DictReader(csvfile)
  46.         database = []
  47.         for row in reader:
  48.             database.append(dict(Name_File = row['first_name'],
  49.                                 LName_File = row['last_name'],
  50.                                 Password_File = row['password'],
  51.                                 Age_File = row['age'],
  52.                                 YearGroup_File = row['year_group']))
  53.     register = False
  54.     while register is not True:
  55.         Name = input('Fill in your name: ')
  56.         database.append(dict(Name_File = row['first_name']))
  57.         LName = input('Fill in your last name: ')
  58.         database.append(dict(LName_File = row['last_name']))
  59.         Age = input('Fill in your age: ')
  60.         database.append(dict(Age = row['age']))
  61.         YearGroup = input('Fill in your year group ')
  62.         database.append(dict(YearGroup = row['year_group']))
  63.         Password = input('Fill in your password ')
  64.         database.append(dict(Password = row['password']))
  65.         Username = (Name[:3]+Age)
  66.         print("Your username is :", Username)
  67.         database.append(dict(Username = row['username']))
  68.         register = True
  69.         print("You've Succesfully Registered")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement