Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''--------------------------------------------------------------------------------------------------------------------
- name: Firestormninja1
- info: OCR GCSE NEA Python Programming Project(will not be assessed in 2018)
- Candidate_number: 7101
- File_name: NEA task1
- Task: Create a music quiz with an operating menu system
- time taken: Days = [[Day1,16hours42minutes],[Day2,x]](list will continue)
- -----------------------------------------------------------------------------------------------------------------------'''
- import random
- import csv
- import tkinter as tk
- from tkinter import *
- import tkinter.font as tkFont
- import string
- from time import sleep as s
- '''--------------------------------------------------------------------------------------------------------------------'''
- ##def generator():
- ## with open('random_usernames.csv','r') as usernames:
- ## reader = csv.reader(usernames)
- ## users = list(reader)
- ## username = str(users).replace('[','').replace(']','')
- ## r_user = username[random.choice(username)]
- ##
- ## with open ('random_passwords.csv','r') as passwords:
- ## read = csv.reader(passwords)
- ## passes = list(read)
- ## password = str(passes).replace('[','').replace(']','')
- ## r_pass = random.choice(username)
- ##
- ## choice = False
- ## while choice == False:
- ## user_choice = input('Would like to generate a random username and password? (Y/N): ').lower()
- ## if user_choice == 'n':
- ## Sign_up()
- ## choice = True
- ## elif user_choice == 'y':
- ## print('Your username: %s and password: %s'%(r_user,r_pass))
- ## choice = True
- ## add_profile(r_user,r_pass)
- ## else:
- ## print('Please enter a valid option')
- ## user_choice = input('Would like to generate a random username and password? (Y/N): ').lower()
- '''--------------------------------------------------------------------------------------------------------------------'''
- def Sign_up():
- with open('QuizD.csv','r') as csvfile:
- reader = csv.reader(csvfile)
- data = list(reader)
- signed = False
- while signed == False:
- Username = input('Please enter a username: ')
- Password = input('Please enter a password: ')
- ## for x in (0,len(data)-1)
- '''See more'''
- ## col0 = [x[0] for x in data]
- ## New_acc = False
- ## while New_acc == False:
- ## for i in range(0,len(data)):
- ## if username != col0[i]:
- ## add_profile(username,password)
- ## New_acc = True
- ## else:
- ## print('Error 404. Username already exists')
- ## username = input('Please enter a username: ')
- ## password = input('Please enter a password: ')
- '''--------------------------------------------------------------------------------------------------------------------'''
- def add_profile(a,b):
- ## with open ('QuizD.csv','a') as csvfil:
- ## fieldnames = ['Usernames','Passwords']
- ## writer = csv.DictWriter(csvfil, fieldnames = fieldnames)
- ## writer.writerow({'Usernames' : a,'Passwords' : b})
- with open('QuizD.csv','a') as f:
- writer = csv.writer(f)
- writer.writerow([a,b])
- f.close()
- print('\nyou may now login as %s'%(a))
- main()
- '''--------------------------------------------------------------------------------------------------------------------'''
- def login():
- '''Best approach'''#------------------------------------------------
- s(0.5)
- Username = input('Enter an already existing user: ')
- Password = input('Enter password: ')
- login = False
- while login == False:
- with open ('QuizD.csv') as csvfile:
- reader = csv.reader(csvfile)
- data = list(reader)
- ## if Username == username:
- '''See more'''
- ## else:
- ## print('Error 404. Incorreect password entered!')
- ## Username = input('Enter an already existing user:')
- ## Password = input('Enter password: ')
- ## else:
- ## print('Error 404. The user %s does not exist.' %(Username))
- ## Username = input('Enter an already existing user: ')
- ## Password = input('Enter password: ')
- '''Alternative approach which doesn't work cuz IDK how to fix it'''
- ## col0 = [x[0] for x in data]#--------------------------------
- ## col1 = [x[1] for x in data]
- ##
- ## if username in col0:
- ## for k in range(0, len(col0)):
- ## if col0[k] == username and col1[k] == password:
- ## print("Login succesfull. Welcome %s"%(username))
- ## login = True
- ## game(username)
- ## break
- ## else:
- ## print('Error 404')#--------------------------------------
- '''--------------------------------------------------------------------------------------------------------------------'''
- def main():
- print('\n***Welcome to The Musiz Quiz***\n')
- while True:
- try:
- inp = int(input('Please choose one of the following: \n1) login \n2) Sign up \n3) Quit \nchoice: '))
- except ValueError:
- print('Please enter an integer.')
- continue
- if inp == 1:
- print('You have chosen to login')
- login()
- break
- elif inp == 2:
- print('you have chosen to sign up')
- Sign_up()
- break
- elif inp == 3:
- print('You have chosen to quit the program')
- tk = Tk()
- master = Tk()
- var = StringVar()
- label = Label( tk, textvariable = var, relief = RAISED, )
- var.set('YOU HAVE CHOSEN TO QUIT THE PROGRAM')
- label.pack()
- tk.geometry('500x300')
- tk.mainloop()
- exit()
- else:
- print('Please enter an input within the range of 1 to 3.')
- tk = Tk()
- master = Tk()
- var = StringVar()
- label = Label( tk, textvariable = var, relief = RAISED, )
- var.set('TO SEE THE FULL CONTENTS OF THIS FILE: \nSUBSCRIBE FOR JUST £99.99!')
- label.pack()
- tk.mainloop()
- #-------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement