Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Imports
- import sys
- import csv
- import time
- import random
- #Varibles
- global score
- score = 0
- musicq = []
- computersq = []
- historyq = []
- #File Connect
- quiz_file = "devcheck.csv"
- music_config = "music.csv"
- computers_config = "computers.csv"
- history_config = "history.csv"
- #Data Drag Prot.
- with open(music_config, 'r') as file:
- reader = csv.reader(file)
- musicq = list(reader)
- with open(computers_config, 'r') as file:
- reader = csv.reader(file)
- computersq = list(reader)
- with open(history_config, 'r') as file:
- reader = csv.reader(file)
- historyq = list(reader)
- #Questions Accumulator
- def ComputersE( qnum ):
- global score
- C_QuE = computersq[qnum][0]
- print("\n",C_QuE)
- #print(C_QuE) #uncomment to see question
- CCAE = computersq[qnum][1]
- CIAH1 = computersq[qnum][2]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", CCAE)
- print("B:", CIAH1)
- elif rNum == 2:
- print("A:", CIAH1)
- print("B:", CCAE)
- elif rNum == 3:
- print("A:", CIAH1)
- print("B:", CCAE)
- elif rNum == 4:
- print("A:", CCAE)
- print("B:", CIAH1)
- elif rNum == 5:
- print("A:", CIAH1)
- print("B:", CCAE)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def ComputersM( qnum ):
- global score
- C_QuM = computersq[qnum][0]
- print("\n",C_QuM)
- #print(C_QuM) #uncomment to see question
- CCAM = computersq[qnum][1]
- CIAM1 = computersq[qnum][2]
- CIAM2 = computersq[qnum][3]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", CCAM)
- print("B:", CIAM1)
- print("C:", CIAM2)
- elif rNum == 2:
- print("A:", CIAM1)
- print("B:", CCAM)
- print("C:", CIAM2)
- elif rNum == 3:
- print("A:", CIAM1)
- print("B:", CIAM2)
- print("C:", CCAM)
- elif rNum == 4:
- print("A:", CIAM1)
- print("B:", CCAM)
- print("C:", CIAM2)
- elif rNum == 5:
- print("A:", CCAM)
- print("B:", CIAM1)
- print("C:", CIAM2)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def ComputersH( qnum ):
- global score
- C_QuH = computersq[qnum][0]
- print("\n",C_QuH)
- #print(C_QuH) #uncomment to see question
- CCAH = computersq[qnum][1]
- CIAH1 = computersq[qnum][2]
- CIAH2 = computersq[qnum][3]
- CIAH3 = computersq[qnum][3]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", CCAH)
- print("B:", CIAH1)
- print("C:", CIAH2)
- print("D:", CIAH3)
- elif rNum == 2:
- print("A:", CIAH1)
- print("B:", CCAH)
- print("C:", CIAH2)
- print("D:", CIAH3)
- elif rNum == 3:
- print("A:", CIAH1)
- print("B:", CIAH2)
- print("C:", CCAH)
- print("D:", CIAH3)
- elif rNum == 4:
- print("A:", CIAH1)
- print("B:", CIAH2)
- print("C:", CIAH3)
- print("D:", CCAH)
- elif rNum == 5:
- print("A:", CIAH1)
- print("B:", CCAH)
- print("C:", CIAH2)
- print("D:", CIAH3)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "D" and rNum ==4:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def MusicE( qnum ):
- global score
- M_QuE = musicq[qnum][0]
- print("\n",M_QuE)
- #print(M_QuE) #uncomment to see question
- MCAE = musicq[qnum][1]
- MIAE1 = musicq[qnum][2]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", MCAE)
- print("B:", MIAE1)
- elif rNum == 2:
- print("A:", MIAE1)
- print("B:", MCAE)
- elif rNum == 3:
- print("A:", MCAE)
- print("B:", MIAE1)
- elif rNum == 4:
- print("A:", MIAE1)
- print("B:", MCAE)
- elif rNum == 5:
- print("A:", MIAE1)
- print("B:", MCAE)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def MusicM( qnum ):
- global score
- M_QuM = musicq[qnum][0]
- print("\n",M_QuM)
- #print(M_QuM) #uncomment to see question
- MCAM = musicq[qnum][1]
- MIAM1 = musicq[qnum][2]
- MIAM2 = musicq[qnum][3]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", MCAM)
- print("B:", MIAM2) #History Incorrect Answer Medium 1
- print("C:", MIAM1)
- elif rNum == 2:
- print("A:", MIAM2)
- print("B:", MCAM)
- print("C:", MIAM1)
- elif rNum == 3:
- print("A:", MIAM2)
- print("B:", MIAM1)
- print("C:", MCAM)
- elif rNum == 4:
- print("A:", MCAM)
- print("B:", MIAM1)
- print("C:", MIAM2)
- elif rNum == 5:
- print("A:", MIAM1)
- print("B:", MCAM)
- print("C:", MIAM2)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def MusicH( qnum ):
- global score
- M_QuH = musicq[qnum][0]
- print("\n",M_QuH)
- #print(M_QuH) #uncomment to see question
- MCAH = musicq[qnum][1]
- MIAH1 = musicq[qnum][2]
- MIAH2 = musicq[qnum][3]
- MIAH3 = musicq[qnum][3]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", MCAH)
- print("B:", MIAH1)
- print("C:", MIAH2)
- print("D:", MIAH3)
- elif rNum == 2:
- print("A:", MIAH1)
- print("B:", MCAH)
- print("C:", MIAH2)
- print("D:", MIAH3)
- elif rNum == 3:
- print("A:", MIAH1)
- print("B:", MIAH2)
- print("C:", MCAH)
- print("D:", MIAH3)
- elif rNum == 4:
- print("A:", MIAH1)
- print("B:", MIAH2)
- print("C:", MIAH3)
- print("D:", MCAH)
- elif rNum == 5:
- print("A:", MIAH1)
- print("B:", MCAH)
- print("C:", MIAH2)
- print("D:", MIAH3)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "D" and rNum ==4:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def HistoryE( qnum ):
- global score
- H_QuE = historyq[qnum][0]
- print("\n",H_QuE)
- #print(H_QuE) #uncomment to see question
- HCAE = historyq[qnum][1]
- HIAE1 = historyq[qnum][2]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", HCAE)
- print("B:", HIAE1)
- elif rNum == 2:
- print("A:", HIAE1)
- print("B:", HCAE)
- elif rNum == 3:
- print("A:", HIAE1)
- print("B:", HCAE)
- elif rNum == 4:
- print("A:", HIAE1)
- print("B:", HCAE)
- elif rNum == 5:
- print("A:", HCAE)
- print("B:", HIAE1)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def HistoryM( qnum ):
- global score
- H_QuM = historyq[qnum][0]
- print("\n",H_QuM)
- #print(H_QuM) #uncomment to see question
- HCAM = historyq[qnum][1]
- HIAM1 = historyq[qnum][2]
- HIAM2 = historyq[qnum][3]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", HCAM)
- print("B:", HIAM1) #History Incorrect Answer Medium 1
- print("C:", HIAM2)
- elif rNum == 2:
- print("A:", HIAM1)
- print("B:", HCAM)
- print("C:", HIAM2)
- elif rNum == 3:
- print("A:", HIAM1)
- print("B:", HIAM2)
- print("C:", HCAM)
- elif rNum == 4:
- print("A:", HCAM)
- print("B:", HIAM2)
- print("C:", HIAM1)
- elif rNum == 5:
- print("A:", HIAM2)
- print("B:", HCAM)
- print("C:", HIAM1)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def HistoryH( qnum ):
- global score
- H_QuH = historyq[qnum][0]
- print("\n",H_QuH)
- #print(H_QuH) #uncomment to see question
- HCAH = historyq[qnum][1]
- HIAH1 = historyq[qnum][2]
- HIAH2 = historyq[qnum][3]
- HIAH3 = historyq[qnum][4]
- rNum = random.randint(1,5)
- if rNum == 1:
- print("A:", HCAH)
- print("B:", HIAH1)
- print("C:", HIAH2)
- print("D:", HIAH3)
- elif rNum == 2:
- print("A:", HIAH1)
- print("B:", HCAH)
- print("C:", HIAH2)
- print("D:", HIAH3) #History Incorrect Answer Hard 3
- elif rNum == 3:
- print("A:", HIAH1)
- print("B:", HIAH2)
- print("C:", HCAH)
- print("D:", HIAH3)
- elif rNum == 4:
- print("A:", HIAH1)
- print("B:", HIAH2)
- print("C:", HIAH3)
- print("D:", HCAH)
- elif rNum == 5:
- print("A:", HCAH)
- print("B:", HIAH1)
- print("C:", HIAH2)
- print("D:", HIAH3)
- answer = input("Please enter your answer: ")
- if answer.upper() == "A" and rNum == 1:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "B" and rNum ==2:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "C" and rNum ==3:
- print("Correct!")
- print("\n")
- score = score +1
- elif answer.upper() == "D" and rNum ==4:
- print("Correct!")
- print("\n")
- score = score +1
- else:
- print("Incorrect!")
- print("\n")
- def report():
- if score == 0:
- time.sleep(1)
- print("==== Quiz Results ====")
- print(" You Scored:", score)
- print(" Your grade is: U")
- print(" Percent: 0%")
- print("======================")
- print("\n")
- print("Thank you for playing!")
- elif score == 1:
- time.sleep(1)
- print("==== Quiz Results ====")
- print(" You Scored:", score)
- print(" Your grade is: D")
- print(" Percent: 20%")
- print("======================")
- print("\n")
- print("Thank you for playing!")
- elif score == 2:
- time.sleep(1)
- print("==== Quiz Results ====")
- print(" You Scored:", score)
- print(" Your grade is: C")
- print(" Percent: 40%")
- print("======================")
- print("\n")
- print("Thank you for playing!")
- elif score == 3:
- time.sleep(1)
- print("==== Quiz Results ====")
- print(" You Scored:", score)
- print(" Your grade is: B")
- print(" Percent: 60%")
- print("======================")
- print("\n")
- print("Thank you for playing!")
- elif score == 4:
- time.sleep(1)
- print("==== Quiz Results ====")
- print(" You Scored:", score)
- print(" Your grade is: A")
- print(" Percent: 80%")
- print("======================")
- print("\n")
- print("Thank you for playing!")
- elif score == 5:
- time.sleep(1)
- print("==== Quiz Results ====")
- print(" You Scored:", score)
- print(" Your grade is: A*")
- print(" Percent: 100%")
- print("======================")
- print("\n")
- print("Thank you for playing!")
- print("=== Main Menu ===")
- print(" A - Take Quiz")
- print(" B - Print Rep")
- print(" C - Exit")
- print("=================")
- usr_action = input()
- if usr_action.upper() == "A":
- print("Welcome to the Quiz! \n Create an account to start.")
- print("\n")
- time.sleep(1)
- print("Please enter the following infomation:")
- time.sleep(1)
- while True:
- try:
- usr_name = []
- usr_name = input("Name: ")
- if usr_name.isdigit():
- print('*You have entered a incorrect value!* \n *Make sure you enter only text!*')
- print("\n")
- else:
- break
- except ValueError:
- print("ERROR! ErrorCode: GS01") #error code here
- while True:
- try:
- usr_age = input("Age: ")
- if usr_age.isdigit(): #checks if its a number
- break
- else:
- print('*You have entered a incorrect value!* \n *Make sure you enter only numerical values here!*')
- print("\n")
- except ValueError:
- print("ERROR! ErrorCode: GS02") #error code here
- while True:
- try:
- usr_yrgrp = input("Year Group:")
- if usr_yrgrp.isdigit(): #checks if its a number
- break
- else:
- print('*You have entered a incorrect value!* \n *Make sure you enter only numerical values here!*')
- print("\n")
- except ValueError:
- print("ERROR! ErrorCode: GS03")
- global usr_username #error code here
- usr_username = usr_name[0] + usr_name[1] + usr_name[2] + str(usr_age)
- print("\n")
- print("Your username is: ",usr_username)
- time.sleep(0.9)
- usr_password = input("Please create a password: ") ## FIX ME PLEASE
- while True:
- try:
- usr_password_re = input("Please retype your password: ")
- print("\n")
- if usr_password == usr_password_re:
- time.sleep(1)
- break
- else:
- print("Password doesn't match! retype password")
- except ValueError:
- print("ERROR! ErrorCode: GS04") #error codes here!
- print("Account created! \n Welcome", usr_username)
- print("\n")
- def writeFile():
- myFile = open('users.txt','a')
- myFile.write("=== User Info ===")
- myFile.write("\n")
- myFile.write("Name: ")
- myFile.write(usr_name)
- myFile.write("\n")
- myFile.write("Age: ")
- myFile.write(usr_age)
- myFile.write("\n")
- myFile.write("Age Group: ")
- myFile.write(usr_yrgrp)
- myFile.write("\n")
- myFile.write("Username: ")
- myFile.write(usr_username)
- myFile.write("\n")
- myFile.write("Password: ")
- myFile.write(usr_password)
- myFile.write("\n")
- myFile.write("Topic: ")
- myFile.write(usr_actop)
- myFile.write("\n")
- myFile.write("Difficulty: ")
- myFile.write(usr_acdiff)
- myFile.write("\n")
- myFile.write("Score: ")
- myFile.write(str(score))
- myFile.write("\n")
- myFile.close()
- print("===== Topic =====")
- print(" A - Computers")
- print(" B - History")
- print(" C - Music")
- print("=================")
- usr_actop = input()
- time.sleep(1)
- if usr_actop.upper() == "A":
- usr_actop = "Computers"
- print("==== Difficulty ====")
- print(" A - Easy")
- print(" B - Medium")
- print(" C - Hard")
- print("====================")
- usr_acdiff = input()
- time.sleep(1)
- if usr_acdiff.upper() == "A":
- usr_acdiff = "Easy"
- for counter in range(5):
- ComputersE(counter)
- report()
- writeFile()
- elif usr_acdiff.upper() == "B":
- usr_acdiff = "Medium"
- for counter in range(5):
- ComputersM(counter)
- report()
- writeFile()
- elif usr_acdiff.upper() == "C":
- usr_acdiff = "Hard"
- for counter in range(5):
- ComputersH(counter)
- report()
- writeFile()
- elif usr_actop.upper() == "B":
- usr_actop = "History"
- print("==== Difficulty ====")
- print(" A - Easy")
- print(" B - Medium")
- print(" C - Hard")
- print("====================")
- usr_acdiff = input()
- time.sleep(1)
- if usr_acdiff.upper() == "A":
- usr_acdiff = "Easy"
- for counter in range(5):
- HistoryE(counter)
- report()
- writeFile()
- elif usr_acdiff.upper() == "B":
- usr_acdiff = "Medium"
- for counter in range(5):
- HistoryM(counter)
- report()
- writeFile()
- elif usr_acdiff.upper() == "C":
- usr_acdiff = "Hard"
- for counter in range(5):
- HistoryH(counter)
- report()
- writeFile()
- elif usr_actop.upper() == "C":
- usr_actop = "Music"
- print("==== Difficulty ====")
- print(" A - Easy")
- print(" B - Medium")
- print(" C - Hard")
- print("====================")
- usr_acdiff = input()
- time.sleep(1)
- if usr_acdiff.upper() == "A":
- usr_acdiff = "Easy"
- for counter in range(5):
- MusicE(counter)
- report()
- writeFile()
- elif usr_acdiff.upper() == "B":
- usr_acdiff = "Medium"
- for counter in range(5):
- MusicM(counter)
- report()
- writeFile()
- elif usr_acdiff.upper() == "C":
- usr_acdiff = "Hard"
- for counter in range(5):
- MusicH(counter)
- report()
- writeFile()
- elif usr_action.upper() == "B":
- print("Print REP HERE!")
- elif usr_action.upper() == "C":
- print("Exiting Program")
- time.sleep(0.5)
- print("Saving Data...")
- time.sleep(0.5)
- print("Exit")
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement