Advertisement
Guest User

AbdiRamen

a guest
Oct 22nd, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.48 KB | None | 0 0
  1. '''--------------------------------------------------------------------------------------------------------------------
  2.  
  3. name: Firestormninja1
  4.    info: OCR GCSE NEA Python Programming Project(will not be assessed in 2018)
  5.    Candidate_number: 7101
  6.    File_name: NEA task1
  7.    Task: Create a music quiz with an operating menu system
  8.    time taken: Days = [[Day1,16hours42minutes],[Day2,x]](list will continue)
  9.  
  10.  
  11. -----------------------------------------------------------------------------------------------------------------------'''
  12.  
  13.  
  14. import random
  15. import csv
  16. import tkinter as tk
  17. from tkinter import *
  18. import tkinter.font as tkFont
  19. import string
  20. from time import sleep as s
  21.  
  22.  
  23.  
  24. '''--------------------------------------------------------------------------------------------------------------------'''
  25.                                            
  26.  
  27. ##def generator():
  28. ##    with open('random_usernames.csv','r') as usernames:
  29. ##        reader = csv.reader(usernames)
  30. ##        users = list(reader)
  31. ##    username = str(users).replace('[','').replace(']','')
  32. ##    r_user = username[random.choice(username)]
  33. ##
  34. ##    with open ('random_passwords.csv','r') as passwords:
  35. ##        read = csv.reader(passwords)
  36. ##        passes = list(read)
  37. ##    password = str(passes).replace('[','').replace(']','')
  38. ##    r_pass = random.choice(username)
  39. ##        
  40. ##    choice = False
  41. ##    while choice == False:
  42. ##        user_choice = input('Would like to generate a random username and password? (Y/N): ').lower()
  43. ##        if user_choice == 'n':
  44. ##            Sign_up()
  45. ##            choice = True
  46. ##        elif user_choice == 'y':
  47. ##            print('Your username: %s and password: %s'%(r_user,r_pass))
  48. ##            choice = True
  49. ##            add_profile(r_user,r_pass)
  50. ##        else:
  51. ##            print('Please enter a valid option')
  52. ##            user_choice = input('Would like to generate a random username and password? (Y/N): ').lower()
  53.  
  54.  
  55. '''--------------------------------------------------------------------------------------------------------------------'''
  56.                                            
  57.  
  58. def Sign_up():
  59.     with open('QuizD.csv','r') as csvfile:
  60.         reader = csv.reader(csvfile)
  61.         data = list(reader)
  62.  
  63.     signed = False
  64.     while signed == False:
  65.         Username = input('Please enter a username: ')
  66.         Password = input('Please enter a password: ')
  67. ##        for x in (0,len(data)-1)
  68. '''See more'''
  69. ##    col0 = [x[0] for x in data]
  70. ##    New_acc = False
  71. ##    while New_acc == False:
  72. ##        for i in range(0,len(data)):
  73. ##            if username != col0[i]:
  74. ##                add_profile(username,password)
  75. ##                New_acc = True
  76. ##            else:
  77. ##                print('Error 404. Username already exists')
  78. ##                username = input('Please enter a username: ')
  79. ##                password = input('Please enter a password: ')
  80.  
  81.  
  82. '''--------------------------------------------------------------------------------------------------------------------'''        
  83.  
  84.  
  85. def add_profile(a,b):
  86. ##    with open ('QuizD.csv','a') as csvfil:
  87. ##        fieldnames = ['Usernames','Passwords']
  88. ##        writer = csv.DictWriter(csvfil, fieldnames = fieldnames)
  89. ##        writer.writerow({'Usernames' : a,'Passwords' : b})
  90.     with open('QuizD.csv','a') as f:
  91.         writer = csv.writer(f)
  92.         writer.writerow([a,b])
  93.         f.close()
  94.     print('\nyou may now login as %s'%(a))
  95.            
  96.     main()
  97.  
  98.  
  99. '''--------------------------------------------------------------------------------------------------------------------'''
  100.  
  101.  
  102. def login():
  103.     '''Best approach'''#------------------------------------------------
  104.     s(0.5)
  105.     Username = input('Enter an already existing user: ')
  106.     Password = input('Enter password: ')
  107.     login = False
  108.     while login == False:
  109.         with open ('QuizD.csv') as csvfile:
  110.             reader = csv.reader(csvfile)
  111.             data = list(reader)
  112. ##          if Username == username:
  113. '''See more'''
  114. ##                else:
  115. ##                    print('Error 404. Incorreect password entered!')
  116. ##                    Username = input('Enter an already existing user:')
  117. ##                    Password = input('Enter password: ')
  118. ##            else:
  119. ##                print('Error 404. The user %s does not exist.' %(Username))
  120. ##                Username = input('Enter an already existing user: ')
  121. ##                Password = input('Enter password: ')
  122. '''Alternative approach which doesn't work cuz IDK how to fix it'''
  123. ##        col0 = [x[0] for x in data]#--------------------------------
  124. ##        col1 = [x[1] for x in data]
  125. ##
  126. ##        if username in col0:
  127. ##            for k in range(0, len(col0)):
  128. ##                if col0[k] == username and col1[k] == password:
  129. ##                    print("Login succesfull. Welcome %s"%(username))
  130. ##                    login = True
  131. ##                    game(username)
  132. ##                    break
  133. ##        else:
  134. ##            print('Error 404')#--------------------------------------
  135.                
  136.  
  137. '''--------------------------------------------------------------------------------------------------------------------'''
  138.  
  139.  
  140. def main():
  141.     print('\n***Welcome to The Musiz Quiz***\n')
  142.     while True:
  143.         try:
  144.             inp = int(input('Please choose one of the following: \n1) login \n2) Sign up \n3) Quit \nchoice: '))
  145.         except ValueError:
  146.             print('Please enter an integer.')
  147.             continue
  148.  
  149.         if inp == 1:
  150.             print('You have chosen to login')
  151.             login()
  152.             break
  153.         elif inp == 2:
  154.             print('you have chosen to sign up')
  155.             Sign_up()
  156.             break
  157.         elif inp == 3:
  158.             print('You have chosen to quit the program')
  159.             tk = Tk()
  160.             master = Tk()
  161.             var = StringVar()
  162.             label = Label( tk, textvariable = var, relief = RAISED, )
  163.             var.set('YOU HAVE CHOSEN TO QUIT THE PROGRAM')
  164.             label.pack()
  165.             tk.geometry('500x300')
  166.             tk.mainloop()
  167.             exit()
  168.         else:
  169.             print('Please enter an input within the range of 1 to 3.')
  170.  
  171. tk = Tk()
  172. master = Tk()
  173. var = StringVar()
  174. label = Label( tk, textvariable = var, relief = RAISED, )
  175. var.set('TO SEE THE FULL CONTENTS OF THIS FILE: \nSUBSCRIBE FOR JUST £99.99!')
  176. label.pack()
  177. tk.mainloop()
  178.  
  179.  
  180. #-------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement