Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys #The QUIT command in every raw_input
- ##Variables
- easyQ_list = ["We live on planet BLANK", "My dad BLANK his car to work", "It is my BLANK every year", "Ssshhh the girl is going to BLANK in the school choir",
- "A monkey BLANK a tree"] #Easy Questions
- medQ_list = ["10 + 10 = BLANK", "11 - 4 = BLANK", "3 x 4 = BLANK", "15 / 5 = BLANK", "8 + 18 = BLANK"] #Medium Questions
- hardQ_list = ["BLANK is home to the Great Barrier Reef", "Nelson Mandela was born in BLANK", "The kiwi (bird) lives in BLANK",
- "BLANK is the capital city of England", "Antartica is at the BLANK pole"] #Hard Questions
- easyA_list = ["EARTH", "DRIVES", "BIRTHDAY", "SING", "CLIMBS"] #Easy Answers
- medA_list = [20, 7, 12, 3, 26] #Medium Answers
- hardA_list = ["AUSTRALIA", "SOUTH AFRICA", "NEW ZEALAND", "LONDON", "SOUTH"] #Hard Answers
- easyCl_list = [ ["mars", "orange", "earth", "moon"], ["is", "drives", "turns", "climbs"],
- ["birthday", "christmas", "happy", "sad"], ["dances", "sing", "sits", "lemon"],
- ["falls", "eat", "climbs", "banana"] ] #Easy Options for Answers
- medCl_list = [ [100, 10, 21, 20], [11, 7, 4, 8], [3, 7, 4, 12], [20, 3, 4, 5], [20, 36, 26, 62] ] #Medium Options for Answers
- hardCl_list = [ ["Sydney", "Australia", "New Zealand", "Thailand"], ["South Africa", "Asia", "India", "Ghana"],
- ["Argentina", "Europe", "New Zealand", "Antartica"], ["Paris", "Ireland", "Manchester", "London"],
- ["South", "West", "North", "East"] ] #Hard Options Answers
- scoreCard = [ [2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2] ] #0 = Incorrect & 1 = Correct & 2 = Missed
- ###############
- def main (): #The main function that is executed
- print "Welcome to my Primary School Quiz \nMade by Jesse T\n"
- print "-- Type QUIT for any answer to exit the Quiz --\n"
- chooseLevel()
- printTotalScore()
- def chooseLevel(): #The level is chosen, and each level is played, all functions are called here
- print "There are 3 levels: "
- nextStep = True
- while (nextStep):
- print "1) Easy: Simple English\n2) Medium: Basic Maths\n3) Hard: International Quiz\n"
- userInput = str(raw_input("Please choose a level number: ")) #Makes input uppercase for easier if statements
- quitGame(userInput)
- if (userInput == '1'):
- startAtE()
- nextStep = False
- elif (userInput == '2'):
- startAtM()
- nextStep = False
- elif (userInput == '3'):
- startAtH()
- nextStep = False
- else:
- print "The level you chose does not exist!\n\nPlease enter the Number of the level you would like to play."
- def easyGame(): #The Easy questions are displayed, answered and marked
- index = 0
- while (index < len(easyQ_list)):
- question = easyQ_list[index].split() #Splits on Single Spaces as Default
- lenAnswer = easyA_list[index]
- printBlank(question, lenAnswer)
- userInput = "" + str(raw_input("Fill in the blank: "))
- print ""
- quitGame(userInput)
- if (easyMarkAnswer(userInput, index)): #Answer given is Correct
- index += 1
- print "That's Correct!"
- else: #incorrect answer, 2nd chance given
- print "You gave the incorrect answer :(\nBut we will give you another chance ;)\n"
- printBlank(question, lenAnswer)
- printSecondChanceE(index)
- easyNewLife(index)
- index += 1
- def medGame(): #The Medium questions are displayed, answered and marked
- index = 0
- while (index < len(medQ_list)):
- print "\nQuestion " + str(index+1)
- question = medQ_list[index].split() #Splits on Single Spaces as Default
- lenAnswer = medA_list[index]
- printBlank(question, lenAnswer)
- userInput = "" + str(raw_input("Complete the sum: "))
- print ""
- quitGame(userInput)
- if (medMarkAnswer(userInput, index)): #Answer given is Correct
- index += 1
- print "That's Correct!"
- else: #incorrect answer, 2nd chance given
- print "You gave the incorrect answer :(\nBut we will give you another chance ;)\n"
- printBlank(question, lenAnswer)
- printSecondChanceM(index)
- medNewLife(index)
- index += 1
- def hardGame(): #The Hard questions are displayed, answered and marked
- index = 0
- while (index < len(hardQ_list)):
- print "\nQuestion " + str(index+1)
- question = hardQ_list[index].split() #Splits on Single Spaces as Default
- lenAnswer = hardA_list[index]
- printBlank(question, lenAnswer)
- userInput = "" + str(raw_input("Fill in the blank: "))
- print ""
- quitGame(userInput)
- if (hardMarkAnswer(userInput, index)): #Answer given is Correct
- index += 1
- print "Thats Correct!"
- else: #incorrect answer, 2nd chance given
- print "You gave the incorrect answer :(\nBut we will give you another chance ;)\n"
- printBlank(question, lenAnswer)
- printSecondChanceH(index)
- hardNewLife(index)
- index += 1
- def easyNewLife (index): #Shortens code in easyGame function (makes it easier for debugging)
- userInput = raw_input("Fill in the blank, by entering the correct number: ")
- quitGame(userInput)
- if (tryInput2(userInput)):
- userInput2 = int(userInput)
- if (userInput2 > 4):
- userInput2 = 1
- if (easyMarkAnswer2(userInput2, index)): #Answer given is Correct
- print "That's Correct!"
- else:
- print "You gave the incorrect answer :(\n"
- def medNewLife (index): #Shortens code in medGame function (makes it easier for debugging)
- userInput = raw_input("Complete the sum, by entering the correct number (1-4): ")
- quitGame(userInput)
- if (tryInput2(userInput)):
- userInput2 = int(userInput)
- if (medMarkAnswer2(userInput2, index)): #Answer given is Correct
- print "That's Correct!"
- else:
- print "That's incorrect :(\n"
- def hardNewLife (index): #Shortens code in easyGame function (makes it easier for debugging)
- userInput = raw_input("Fill in the blank, by entering the correct number: ")
- quitGame(userInput)
- if (tryInput2(userInput)):
- userInput2 = int(userInput)
- if (hardMarkAnswer2(userInput2, index)): #Answer given is Correct
- print "That's Correct!"
- else:
- print "You gave the incorrect answer :(\n"
- def startAtM (): #Shortens the lines in chooseLevel function (easier for debugging)
- print "\nMedium: Basic Maths\n" + "-"*19
- medGame()
- printScoreCard(2)
- nextLevel = raw_input("Do you want to play the next level? (y) or (n)")
- quitGame(nextLevel)
- if (nextLevel.upper() == 'Y'):
- print "\nHard: International Quiz\n" + "-"*24
- hardGame()
- def startAtH (): #Shortens the lines in chooseLevel function (easier for debugging)
- print "\nHard: International Quiz\n" + "-"*24
- hardGame()
- def startAtE (): #Shortens the lines in chooseLevel function (easier for debugging)
- print "\nEasy: Simple English\n" + "-"*21
- easyGame()
- printScoreCard(1)
- nextLevel = raw_input("Do you want to play the next level? (y) or (n)")
- quitGame(nextLevel)
- if (nextLevel.upper() == 'Y'):
- print "\nMedium: Basic Maths\n" + "-"*19
- medGame()
- printScoreCard(2)
- nextLevel = raw_input("Do you want to play the next level? (y) or (n)")
- quitGame(nextLevel)
- if (nextLevel.upper() == 'Y'):
- print "\nHard: International Quiz\n" + "-"*24
- hardGame()
- def printTotalScore(): #Displays the total score from all levels
- correct = 0
- total = 0
- print "Your Results\n" + '*'*12
- for index in range(len(scoreCard)):
- if (sum(scoreCard[index]) == 10):
- print "Level " + str(index+1) + ": Skipped"
- else:
- print "Level " + str(index+1) + ": " + str(sum(scoreCard[index])) + "/5"
- correct += sum(scoreCard[index])
- total += 5
- print '*'*12 + "\nTotal Score: " + str(correct) + "/" + str(total)
- print "\nWell Done!\nThank you for playing the game\nGoodbye :)"
- def printScoreCard(levelNum): #Displays the score out of 5 of the current level
- congrats = "Well Done! You finished level " + str(levelNum)
- print congrats + '\n' + '*'*len(congrats)
- sum = 0
- var = 0
- while(var < 5):
- if (scoreCard[levelNum-1][var] == 1):
- sum += 1
- var += 1
- print "Your score was " + str(sum) + "/5."
- if (sum < 3):
- print "Sorry, but you need to get 50% or more to pass the level.\nGo back and Study a bit more and then try again :)"
- print "Goodbye and Goodluck!"
- sys.exit()
- def printBlank(question, lenAnswer):#Prints out Statement with ___ instead of BLANK
- newQuestion = [ ]
- sentence = ""
- spot = 0
- while (spot < len(question)):
- if (question[spot] != "BLANK"):
- word = question[spot] + " "
- newQuestion.append(word)
- else:
- try:
- word = "_"*len(lenAnswer)
- except TypeError:
- word = "?"
- newQuestion.append(word)
- else:
- word = "_"*len(lenAnswer)
- newQuestion.append(word)
- spot += 1
- sentence = " ".join(newQuestion)
- print sentence
- def easyMarkAnswer(userInput, index): #Checks to see if the easy answer is correct
- if (userInput.upper() == easyA_list[index]):
- scoreCard[0][index] = 1
- return True
- else:
- return False
- def medMarkAnswer(userInput, index): #Checks to see if the medium answer is correct
- if (int(userInput) == medA_list[index]):
- scoreCard[1][index] = 1
- return True
- else:
- return False
- def hardMarkAnswer(userInput, index): #Checks to see if the hard answer is correct
- if (userInput.upper() == hardA_list[index]):
- scoreCard[2][index] = 1
- return True
- else:
- return False
- def easyMarkAnswer2(userInput2, index): #Checks to see if the 2nd easy answer is correct
- print ""
- if (easyCl_list[index][userInput2-1].upper() == easyA_list[index]):
- scoreCard[0][index] = 1
- return True
- else:
- scoreCard[0][index] = 0
- return False
- def medMarkAnswer2(userInput2, index): #Checks to see if the 2nd medium answer is correct
- print ""
- if (medCl_list[index][userInput2-1] == medA_list[index]):
- scoreCard[1][index] = 1
- return True
- else:
- scoreCard[1][index] = 0
- return False
- def hardMarkAnswer2(userInput2, index): #Checks to see if the 2nd hard answer is correct
- print ""
- if (hardCl_list[index][userInput2-1].upper() == hardA_list[index]):
- scoreCard[2][index] = 1
- return True
- else:
- scoreCard[2][index] = 0
- return False
- def printSecondChanceE (index): #Displays the 4 Easy options as answers
- indexVar = 0
- while (indexVar < len(easyCl_list[index])):
- print "" + str(indexVar+1) + ') ' + easyCl_list[index][indexVar]
- indexVar += 1
- def printSecondChanceM (index): #Displays the 4 Medium options as answers
- indexVar = 0
- while (indexVar < len(medCl_list[index])):
- print "" + str(indexVar+1) + ') ' + str(medCl_list[index][indexVar])
- indexVar += 1
- def printSecondChanceH (index): #Displays the 4 Hard options as answers
- indexVar = 0
- while (indexVar < len(hardCl_list[index])):
- print "" + str(indexVar+1) + ') ' + hardCl_list[index][indexVar]
- indexVar += 1
- def quitGame(quit): #At any point if QUIT is entered the program exits
- if (quit.upper() == "QUIT"):
- print "You have exited the Quiz, Goodbye :)"
- sys.exit()
- def tryInput2(userInput): #Checks to see if the user inputs a integer instead of a string and prevents the program from crashing
- try:
- userInput2 = int(userInput)
- except Exception:
- print "Invalid Answer!\nPlease read Question carefully, and Restart Game."
- sys.exit()
- else:
- return True
- ###MAIN###
- main() #Executes the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement