Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def Trivia():
- score = 0
- print("maths")
- print("science")
- Quiz = raw_input("Pick a Subject(Please type in no caps):")
- QuizFile = open(Quiz+".txt","r") # opens the CSV file and stores it in the array myFile
- lines = QuizFile.readlines() # reads the lines of the CSV file into the variable players
- QuestionNO=1
- print("Choose your Difficutly:")
- print("1.Easy")
- print("2.Medium")
- print("3.Hard")
- Difficultychoice = int(raw_input("Enter a choice(1-3)"))
- if Difficultychoice == 1:
- QuizFile = open(Quiz+".txt","r") # opens the CSV file and stores it in the array myFile
- lines = QuizFile.readlines() # reads the lines of the CSV file into the variable players
- QuestionNO=1
- for details in lines:
- data = details.split(",") #splits each cell of the CSV file into its part
- questions = data[0]
- answera = data[1] #These 6 codes assigns the individual data in the text file to variables
- answerb = data[4] #
- correctanswer = data[5]
- print(correctanswer)
- print("Question #",QuestionNO)
- print(questions) #prints the question and the 4 answers
- print("1. " +answera) #
- print("2. " +answerb) #
- A1= raw_input("Input Your Answer(Make sure you enter a full answer):")#asks the user for their answer
- print(".")
- print(".")
- print(".")
- if A1 == correctanswer: #checks if the answer is correct and prints approptiate responses
- print("That is the correct answer")
- score=score+1 #adds a point to your ovwerall score everytime you get the answer right
- else:
- print("That is not the correct answer.(Make sure you enter the full answer)")
- print("Your current score is", score)
- print("")
- QuestionNO = QuestionNO+1 #this adds 1 to the variable QuestionNO, this is to loop the whole code till thwe variable questionNO is 10
- QuizFile.close()
- elif Difficultychoice == 2:
- QuizFile = open(Quiz+".txt","r") # opens the CSV file and stores it in the array myFile
- lines = QuizFile.readlines() # reads the lines of the CSV file into the variable players
- QuestionNO=1
- for details in lines:
- data = details.split(",") #splits each cell of the CSV file into its part
- questions = data[0]
- answera = data[1] #These 6 codes assigns the individual data in the text file to variables
- answerb = data[2] #
- answerc = data[4] #
- correctanswer = data[5]
- print(correctanswer)
- print("Question #",QuestionNO)
- print(questions) #prints the question and the 4 answers
- print("1. " +answerb) #
- print("2. " +answera) #
- print("3. " +answerc) #
- A1= raw_input("Input Your Answer(Make sure you enter a full answer):")#asks the user for their answer
- print(".")
- print(".")
- print(".")
- if A1 == correctanswer: #checks if the answer is correct and prints approptiate responses
- print("That is the correct answer")
- score=score+1 #adds a point to your ovwerall score everytime you get the answer right
- else:
- print("That is not the correct answer.(Make sure you enter the full answer)")
- print("Your current score is", score)
- print("")
- QuestionNO = QuestionNO+1 #this adds 1 to the variable QuestionNO, this is to loop the whole code till thwe variable questionNO is 10
- QuizFile.close()
- elif Difficultychoice == 3:
- QuizFile = open(Quiz+".txt","r") # opens the CSV file and stores it in the array myFile
- lines = QuizFile.readlines() # reads the lines of the CSV file into the variable players
- QuestionNO=1
- for details in lines:
- data = details.split(",") #splits each cell of the CSV file into its part
- questions = data[0]
- answera = data[1] #These 6 codes assigns the individual data in the text file to variables
- answerb = data[2] #
- answerc = data[3] #
- answerd = data[4] #
- correctanswer = data[5]
- print(correctanswer)
- print("Question #",QuestionNO)
- print(questions) #prints the question and the 4 answers
- print("1. " +answera) #
- print("2. " +answerb) #
- print("3. " +answerc) #
- print("4. " +answerd) #
- A1= raw_input("Input Your Answer(Make sure you enter a full answer):")#asks the user for their answer
- print(".")
- print(".")
- print(".")
- if A1 == correctanswer: #checks if the answer is correct and prints approptiate responses
- print("That is the correct answer")
- score=score+1 #adds a point to your ovwerall score everytime you get the answer right
- else:
- print("That is not the correct answer.(Make sure you enter the full answer)")
- print("Your current score is", score)
- print("")
- QuestionNO = QuestionNO+1 #this adds 1 to the variable QuestionNO, this is to loop the whole code till thwe variable questionNO is 10
- QuizFile.close()
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement