Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.64 KB | None | 0 0
  1. import sys #The QUIT command in every raw_input
  2. ##Variables
  3. 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",
  4. "A monkey BLANK a tree"] #Easy Questions
  5. medQ_list = ["10 + 10 = BLANK", "11 - 4 = BLANK", "3 x 4 = BLANK", "15 / 5 = BLANK", "8 + 18 = BLANK"] #Medium Questions
  6. hardQ_list = ["BLANK is home to the Great Barrier Reef", "Nelson Mandela was born in BLANK", "The kiwi (bird) lives in BLANK",
  7. "BLANK is the capital city of England", "Antartica is at the BLANK pole"] #Hard Questions
  8.  
  9. easyA_list = ["EARTH", "DRIVES", "BIRTHDAY", "SING", "CLIMBS"] #Easy Answers
  10. medA_list = [20, 7, 12, 3, 26] #Medium Answers
  11. hardA_list = ["AUSTRALIA", "SOUTH AFRICA", "NEW ZEALAND", "LONDON", "SOUTH"] #Hard Answers
  12.  
  13. easyCl_list = [ ["mars", "orange", "earth", "moon"], ["is", "drives", "turns", "climbs"],
  14. ["birthday", "christmas", "happy", "sad"], ["dances", "sing", "sits", "lemon"],
  15. ["falls", "eat", "climbs", "banana"] ] #Easy Options for Answers
  16. 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
  17. hardCl_list = [ ["Sydney", "Australia", "New Zealand", "Thailand"], ["South Africa", "Asia", "India", "Ghana"],
  18. ["Argentina", "Europe", "New Zealand", "Antartica"], ["Paris", "Ireland", "Manchester", "London"],
  19. ["South", "West", "North", "East"] ] #Hard Options Answers
  20.  
  21. scoreCard = [ [2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2] ] #0 = Incorrect & 1 = Correct & 2 = Missed
  22. ###############
  23.  
  24. def main (): #The main function that is executed
  25. print "Welcome to my Primary School Quiz \nMade by Jesse T\n"
  26. print "-- Type QUIT for any answer to exit the Quiz --\n"
  27. chooseLevel()
  28. printTotalScore()
  29.  
  30. def chooseLevel(): #The level is chosen, and each level is played, all functions are called here
  31. print "There are 3 levels: "
  32. nextStep = True
  33. while (nextStep):
  34. print "1) Easy: Simple English\n2) Medium: Basic Maths\n3) Hard: International Quiz\n"
  35. userInput = str(raw_input("Please choose a level number: ")) #Makes input uppercase for easier if statements
  36. quitGame(userInput)
  37. if (userInput == '1'):
  38. startAtE()
  39. nextStep = False
  40. elif (userInput == '2'):
  41. startAtM()
  42. nextStep = False
  43. elif (userInput == '3'):
  44. startAtH()
  45. nextStep = False
  46. else:
  47. print "The level you chose does not exist!\n\nPlease enter the Number of the level you would like to play."
  48.  
  49. def easyGame(): #The Easy questions are displayed, answered and marked
  50. index = 0
  51. while (index < len(easyQ_list)):
  52. question = easyQ_list[index].split() #Splits on Single Spaces as Default
  53. lenAnswer = easyA_list[index]
  54. printBlank(question, lenAnswer)
  55.  
  56. userInput = "" + str(raw_input("Fill in the blank: "))
  57. print ""
  58. quitGame(userInput)
  59.  
  60. if (easyMarkAnswer(userInput, index)): #Answer given is Correct
  61. index += 1
  62. print "That's Correct!"
  63. else: #incorrect answer, 2nd chance given
  64. print "You gave the incorrect answer :(\nBut we will give you another chance ;)\n"
  65. printBlank(question, lenAnswer)
  66. printSecondChanceE(index)
  67. easyNewLife(index)
  68. index += 1
  69.  
  70. def medGame(): #The Medium questions are displayed, answered and marked
  71. index = 0
  72. while (index < len(medQ_list)):
  73. print "\nQuestion " + str(index+1)
  74. question = medQ_list[index].split() #Splits on Single Spaces as Default
  75. lenAnswer = medA_list[index]
  76. printBlank(question, lenAnswer)
  77.  
  78. userInput = "" + str(raw_input("Complete the sum: "))
  79. print ""
  80. quitGame(userInput)
  81.  
  82. if (medMarkAnswer(userInput, index)): #Answer given is Correct
  83. index += 1
  84. print "That's Correct!"
  85. else: #incorrect answer, 2nd chance given
  86. print "You gave the incorrect answer :(\nBut we will give you another chance ;)\n"
  87. printBlank(question, lenAnswer)
  88. printSecondChanceM(index)
  89. medNewLife(index)
  90. index += 1
  91.  
  92. def hardGame(): #The Hard questions are displayed, answered and marked
  93. index = 0
  94. while (index < len(hardQ_list)):
  95. print "\nQuestion " + str(index+1)
  96. question = hardQ_list[index].split() #Splits on Single Spaces as Default
  97. lenAnswer = hardA_list[index]
  98. printBlank(question, lenAnswer)
  99.  
  100. userInput = "" + str(raw_input("Fill in the blank: "))
  101. print ""
  102. quitGame(userInput)
  103.  
  104. if (hardMarkAnswer(userInput, index)): #Answer given is Correct
  105. index += 1
  106. print "Thats Correct!"
  107. else: #incorrect answer, 2nd chance given
  108. print "You gave the incorrect answer :(\nBut we will give you another chance ;)\n"
  109. printBlank(question, lenAnswer)
  110. printSecondChanceH(index)
  111. hardNewLife(index)
  112. index += 1
  113.  
  114. def easyNewLife (index): #Shortens code in easyGame function (makes it easier for debugging)
  115. userInput = raw_input("Fill in the blank, by entering the correct number: ")
  116. quitGame(userInput)
  117. if (tryInput2(userInput)):
  118. userInput2 = int(userInput)
  119. if (userInput2 > 4):
  120. userInput2 = 1
  121. if (easyMarkAnswer2(userInput2, index)): #Answer given is Correct
  122. print "That's Correct!"
  123. else:
  124. print "You gave the incorrect answer :(\n"
  125.  
  126. def medNewLife (index): #Shortens code in medGame function (makes it easier for debugging)
  127. userInput = raw_input("Complete the sum, by entering the correct number (1-4): ")
  128. quitGame(userInput)
  129. if (tryInput2(userInput)):
  130. userInput2 = int(userInput)
  131.  
  132. if (medMarkAnswer2(userInput2, index)): #Answer given is Correct
  133. print "That's Correct!"
  134. else:
  135. print "That's incorrect :(\n"
  136.  
  137. def hardNewLife (index): #Shortens code in easyGame function (makes it easier for debugging)
  138. userInput = raw_input("Fill in the blank, by entering the correct number: ")
  139. quitGame(userInput)
  140. if (tryInput2(userInput)):
  141. userInput2 = int(userInput)
  142.  
  143. if (hardMarkAnswer2(userInput2, index)): #Answer given is Correct
  144. print "That's Correct!"
  145. else:
  146. print "You gave the incorrect answer :(\n"
  147.  
  148. def startAtM (): #Shortens the lines in chooseLevel function (easier for debugging)
  149. print "\nMedium: Basic Maths\n" + "-"*19
  150. medGame()
  151. printScoreCard(2)
  152. nextLevel = raw_input("Do you want to play the next level? (y) or (n)")
  153. quitGame(nextLevel)
  154. if (nextLevel.upper() == 'Y'):
  155. print "\nHard: International Quiz\n" + "-"*24
  156. hardGame()
  157.  
  158. def startAtH (): #Shortens the lines in chooseLevel function (easier for debugging)
  159. print "\nHard: International Quiz\n" + "-"*24
  160. hardGame()
  161.  
  162. def startAtE (): #Shortens the lines in chooseLevel function (easier for debugging)
  163. print "\nEasy: Simple English\n" + "-"*21
  164. easyGame()
  165. printScoreCard(1)
  166. nextLevel = raw_input("Do you want to play the next level? (y) or (n)")
  167. quitGame(nextLevel)
  168. if (nextLevel.upper() == 'Y'):
  169. print "\nMedium: Basic Maths\n" + "-"*19
  170. medGame()
  171. printScoreCard(2)
  172. nextLevel = raw_input("Do you want to play the next level? (y) or (n)")
  173. quitGame(nextLevel)
  174. if (nextLevel.upper() == 'Y'):
  175. print "\nHard: International Quiz\n" + "-"*24
  176. hardGame()
  177.  
  178. def printTotalScore(): #Displays the total score from all levels
  179. correct = 0
  180. total = 0
  181. print "Your Results\n" + '*'*12
  182. for index in range(len(scoreCard)):
  183. if (sum(scoreCard[index]) == 10):
  184. print "Level " + str(index+1) + ": Skipped"
  185. else:
  186. print "Level " + str(index+1) + ": " + str(sum(scoreCard[index])) + "/5"
  187. correct += sum(scoreCard[index])
  188. total += 5
  189. print '*'*12 + "\nTotal Score: " + str(correct) + "/" + str(total)
  190. print "\nWell Done!\nThank you for playing the game\nGoodbye :)"
  191.  
  192. def printScoreCard(levelNum): #Displays the score out of 5 of the current level
  193. congrats = "Well Done! You finished level " + str(levelNum)
  194. print congrats + '\n' + '*'*len(congrats)
  195. sum = 0
  196. var = 0
  197. while(var < 5):
  198. if (scoreCard[levelNum-1][var] == 1):
  199. sum += 1
  200. var += 1
  201. print "Your score was " + str(sum) + "/5."
  202. if (sum < 3):
  203. 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 :)"
  204. print "Goodbye and Goodluck!"
  205. sys.exit()
  206.  
  207. def printBlank(question, lenAnswer):#Prints out Statement with ___ instead of BLANK
  208. newQuestion = [ ]
  209. sentence = ""
  210. spot = 0
  211. while (spot < len(question)):
  212. if (question[spot] != "BLANK"):
  213. word = question[spot] + " "
  214. newQuestion.append(word)
  215. else:
  216. try:
  217. word = "_"*len(lenAnswer)
  218. except TypeError:
  219. word = "?"
  220. newQuestion.append(word)
  221. else:
  222. word = "_"*len(lenAnswer)
  223. newQuestion.append(word)
  224. spot += 1
  225. sentence = " ".join(newQuestion)
  226. print sentence
  227.  
  228. def easyMarkAnswer(userInput, index): #Checks to see if the easy answer is correct
  229. if (userInput.upper() == easyA_list[index]):
  230. scoreCard[0][index] = 1
  231. return True
  232. else:
  233. return False
  234.  
  235. def medMarkAnswer(userInput, index): #Checks to see if the medium answer is correct
  236. if (int(userInput) == medA_list[index]):
  237. scoreCard[1][index] = 1
  238. return True
  239. else:
  240. return False
  241. def hardMarkAnswer(userInput, index): #Checks to see if the hard answer is correct
  242. if (userInput.upper() == hardA_list[index]):
  243. scoreCard[2][index] = 1
  244. return True
  245. else:
  246. return False
  247.  
  248. def easyMarkAnswer2(userInput2, index): #Checks to see if the 2nd easy answer is correct
  249. print ""
  250. if (easyCl_list[index][userInput2-1].upper() == easyA_list[index]):
  251. scoreCard[0][index] = 1
  252. return True
  253. else:
  254. scoreCard[0][index] = 0
  255. return False
  256.  
  257. def medMarkAnswer2(userInput2, index): #Checks to see if the 2nd medium answer is correct
  258. print ""
  259. if (medCl_list[index][userInput2-1] == medA_list[index]):
  260. scoreCard[1][index] = 1
  261. return True
  262. else:
  263. scoreCard[1][index] = 0
  264. return False
  265. def hardMarkAnswer2(userInput2, index): #Checks to see if the 2nd hard answer is correct
  266. print ""
  267. if (hardCl_list[index][userInput2-1].upper() == hardA_list[index]):
  268. scoreCard[2][index] = 1
  269. return True
  270. else:
  271. scoreCard[2][index] = 0
  272. return False
  273.  
  274. def printSecondChanceE (index): #Displays the 4 Easy options as answers
  275. indexVar = 0
  276. while (indexVar < len(easyCl_list[index])):
  277. print "" + str(indexVar+1) + ') ' + easyCl_list[index][indexVar]
  278. indexVar += 1
  279.  
  280. def printSecondChanceM (index): #Displays the 4 Medium options as answers
  281. indexVar = 0
  282. while (indexVar < len(medCl_list[index])):
  283. print "" + str(indexVar+1) + ') ' + str(medCl_list[index][indexVar])
  284. indexVar += 1
  285. def printSecondChanceH (index): #Displays the 4 Hard options as answers
  286. indexVar = 0
  287. while (indexVar < len(hardCl_list[index])):
  288. print "" + str(indexVar+1) + ') ' + hardCl_list[index][indexVar]
  289. indexVar += 1
  290.  
  291. def quitGame(quit): #At any point if QUIT is entered the program exits
  292. if (quit.upper() == "QUIT"):
  293. print "You have exited the Quiz, Goodbye :)"
  294. sys.exit()
  295. def tryInput2(userInput): #Checks to see if the user inputs a integer instead of a string and prevents the program from crashing
  296. try:
  297. userInput2 = int(userInput)
  298. except Exception:
  299. print "Invalid Answer!\nPlease read Question carefully, and Restart Game."
  300. sys.exit()
  301. else:
  302. return True
  303. ###MAIN###
  304. main() #Executes the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement