Advertisement
Guest User

Untitled

a guest
Jun 1st, 2014
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.03 KB | None | 0 0
  1. #This program will give a user the option to select a category
  2. #From that category, the user will be asked a series of questions
  3. #The user is awarded 1 point for each correct answer
  4. #If the user scores 5 points, they are able to create a question
  5. #The user has a "cheat" if you select 5, you auto pass and get a point
  6. #if the user chooses 5 and already used the cheat, they will -1 point.
  7.  
  8.  
  9. # This is the orginal list for the questions
  10.  
  11.  
  12. sci =[{"question":"How old is the earth?",
  13.            "choice":["1. 4.8 BYO.","2. 5.5 BYO.","3. 6,000 years.",
  14.                      "4. 65 MYO."],"answer":1},
  15.  
  16.       {"question":"What planet is closest in size to our moon?",
  17.            "choice":["1. Venus","2. Mercury",
  18.            "3. Jupiter","4. Pluto"],"answer":2},
  19.  
  20.  
  21. {"question":"What's the base unit of mass in the metric system?",                #questions for science category
  22.            "choice":["1. Pounds","2. Liters",
  23.            "3.Jouls","4. Kilograms"],"answer":4},
  24.  
  25. {"question":"What energy unit is defined as the heat required to raise one kilogram of water by one degree Celsius?",
  26.            "choice":["1. One Calorie.","2.One KCalorie",
  27.            "3.One Joul","4. One Degree F"],"answer":1},
  28.  
  29. {"question":"What's the most malleable metal?",
  30.            "choice":["1. Silver","2. Gold",
  31.            "3. Copper","4. Steel"],"answer":2}]
  32.  
  33.  
  34.  
  35. import sys
  36. import time
  37. from guestionGivefunc import addQ,sciquestionAsk,popquestionAsk
  38. import pickle
  39. sciIn = open('sciList.txt','rb')
  40. sci = pickle.load(sciIn)
  41.  
  42. def addQ():
  43.     dicQ = {}
  44.     userChoice=[]
  45.     userCat = int(input("Please select which category you would like to add too. "))
  46.     question = input("Please type your question: ")
  47.     dicQ["question"] = question
  48.     userChoice.append(input("please type choice 1. "))
  49.     userChoice.append(input("please type choice 2. "))
  50.     userChoice.append(input("please type choice 3. "))            #This function is to create a question to add if you achive a perfect score
  51.     userChoice.append(input("please type choice 4. "))
  52.     dicQ["choice"]= userChoice
  53.     answer = int(input("Type the answer 1-4: " ))
  54.     dicQ["answer"]= answer
  55.     if userCat == 1:
  56.         sciOut = open("sciList.txt",'wb')
  57.         sci.append(dicQ)
  58.         pickle.dump(sci, sciOut)
  59.         sciOut.close()
  60.  
  61.  
  62.     elif userCat == 2:
  63.         pop.append(dicQ)
  64.    
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. def sciquestionAsk():
  72.     global points
  73.     count = 0
  74.     cheat = 1
  75.    
  76.     while count < len(sci):
  77.         print(sci[count]['question'])
  78.         time.sleep(.5)#Timing
  79.         print("\n") #pulls count and question down the list of dicts
  80.         print("\n")
  81.         print(sci[count]['choice']) #prints the choices to choose from
  82.         time.sleep(.5)
  83.         print("\n")
  84.         print("\n")
  85.         answer = int(input("Please select your choice: "))
  86.         print("\n")
  87.         print("\n")
  88.         if sci[count]["answer"]==answer:
  89.             print("\n")
  90.             time.sleep(.5) #Timing
  91.             print("\n")      #Checks to see if correct answer was givin and awards points
  92.             print("""
  93. __________________________________________________
  94. I                                                I
  95. I              THAT IS CORRECT!!                 I
  96. I                                                I
  97. I                 1 POINT!                       I
  98. I                                                I
  99. __________________________________________________
  100.  
  101. """)
  102.             print("\n")
  103.             print("\n")
  104.             points += 1
  105.             print("You earned 1 points!")
  106.             time.sleep(1) #Timing
  107.             print("\n")
  108.             print("\n")
  109.             print("You now have ",points,"points!")
  110.         elif answer == 5 and cheat == 1:#This section adds the cheat option of "5"
  111.             print("You used your cheat")
  112.             cheat -= 1
  113.             points += 1
  114.         elif answer == 5 and cheat != 1: #This is what happens if they try to cheat and fail
  115.             print("You do not have a cheat.")
  116.             print("Therefore your answer is incorrect.")
  117.             print("Cheaters shall be punished. -1 points")
  118.             points -= 1
  119.             print("You now have,",points,"points.")
  120.            
  121.         else:   #this is the incorrect message, displays points and shows correct answer
  122.             print("""
  123. __________________________________________________
  124. I                                                I
  125. I              THAT IS INCORRECT!!               I
  126. I                                                I
  127. I                 0 POINTs                       I
  128. I                                                I
  129. __________________________________________________
  130.  
  131. """)
  132.             print("The correct answer was",sci[count]["answer"])
  133.             time.sleep(.5) #Timing
  134.             print("You have ",points, "points.")
  135.  
  136.         count+=1
  137.  
  138. print("\n")
  139. print("\n")
  140.  
  141.  
  142.  
  143.  
  144. def popquestionAsk():
  145.     count=0
  146.     global points
  147.     cheat = 1
  148.     while count < len(pop):
  149.         print(pop[count]['question'])
  150.         time.sleep(.5) #Timing
  151.         print("\n")
  152.         print("\n")
  153.         print(pop[count]['choice'])
  154.         time.sleep(.5) #Timing
  155.         print("\n")
  156.         print("\n")
  157.  
  158.         answer = int(input("Please select your choice: "))
  159.         time.sleep(.5) #Timing
  160.         print("\n")
  161.         print("\n")
  162.         if pop[count]["answer"]==answer:
  163.             print("\n")
  164.             print("\n")
  165.             print("""
  166. __________________________________________________
  167. I                                                I
  168. I              THAT IS CORRECT!!                 I
  169. I                                                I
  170. I                 1 POINT!                       I
  171. I                                                I
  172. __________________________________________________
  173.  
  174. """)
  175.             print("\n")
  176.             print("\n")
  177.             points+=1
  178.             print("You earned 1 point!")
  179.             time.sleep(.5) #Timing
  180.             print("\n")
  181.             print("\n")
  182.             print("You now have, ",points,"points!")
  183.         elif answer == 5 and cheat == 1:#This section adds the cheat option of "5"
  184.             print("You used your cheat, and gained a point!")
  185.             print("\n")
  186.             print("\n")
  187.             cheat -= 1
  188.             points += 1
  189.         elif answer == 5 and cheat != 1: #This is what happens if they try to cheat and fail
  190.             print("You do not have a cheat.")
  191.             print("Therefore your answer is incorrect.")
  192.             print("Cheaters shall be punished. -1 points")
  193.             points -= 1
  194.             print("You now have,",points,"points.")
  195.            
  196.         else:
  197.             print("""
  198. __________________________________________________
  199. I                                                I
  200. I              THAT IS INCORRECT!!               I
  201. I                                                I
  202. I                 0 POINTS                       I
  203. I                                                I
  204. __________________________________________________
  205.  
  206. """)
  207.             print("The correct answer was",pop[count]["answer"])
  208.             time.sleep(.5) #Timing
  209.             print("You have ",points, "points.")
  210.  
  211.         count=count + 1
  212.  
  213.  
  214. pop =[
  215.  
  216. {"question":"Complete this lyric:“We don’t care, we’re driving ________in our dreams.”?",
  217.            "choice":["1. Vespas.","2. Cadillacs.",
  218.            "3. Golf Balls.","4.The Enterprise."],"answer":2.},
  219.  
  220.  
  221. {"question":"Which pop star was named after a professional wrestler?",
  222.            "choice":["1.Psy.","2.Lorde.",
  223.            "3. Bruno Mars.","4. Justin 'The Hulk' Bieber."],"answer":3},          #questions for pop culture category
  224.  
  225. {"question":"The quote 'It's a trap!' comes from this...?",
  226.            "choice":["1. Half-Life.","2. Star Wars.",
  227.            "3. Star Trek.","4. Space Balls."],"answer":2},
  228.  
  229. {"question":"Avengers, X-Men and Spider-man are all set in this univese named after the comic books...?",
  230.            "choice":["1. DC.","2. Dark Horse.",
  231.            "3. Marvel.","4. Action Comics."],"answer":3},
  232.      
  233. {"question":"Which of the following TV shows is a spin-off of the mega-hit show 'Breaking Bad'?",
  234.            "choice":["1. Better Call Saul.","2. Battle Creek.",
  235.            "3. Breakfast with Jr.","4. Jesse and James."],"answer":1}
  236.  
  237.  
  238.       ]
  239.  
  240.  
  241.  
  242. global points
  243. points = 0
  244. #starts count to run though category list
  245.  
  246.  
  247.  
  248. print("\n")                  #intro pssst, for a cheat, try using option 5
  249. print("""
  250. _________Welcome to the TRIVIA CHALLENGE!_________
  251. I                                                I
  252. I             Choose a Category!                 I
  253. I                                                I              
  254. I       1.Science             2.Pop Culture      I
  255. I                                                I
  256. __________________________________________________
  257.  
  258. """)
  259.  
  260.  
  261. print("\n")
  262. print("\n")
  263. time.sleep(.5)#Timing
  264. cat = int(input("What Category would you like? "))
  265. print("\n")
  266. print("\n")
  267.  
  268.  
  269. #Starts the question process depending on the category selected
  270. if cat == 1:
  271.     sciIn.close()
  272.     sciquestionAsk()
  273.  
  274. if cat == 2: #same as cat 1 with pop replacing sci
  275.     popquestionAsk()
  276.    
  277.  
  278. if points > 4: #This begins the process to add a question. You must have gotten 5 points to access this screen.
  279.     print("""
  280. __________________________________________________
  281. I                CONGRATULATIONS!!!              I
  282. I                                                I
  283. I                                                I
  284. I          YOU CAN NOW ADD A QUESTION!           I
  285. I                                                I
  286. I        Choose 1 for Science                    I
  287. I        Choose 2 for Pop Culture                I
  288. I                                                I
  289. I                                                I
  290. __________________________________________________
  291.  
  292. """)
  293.  
  294.     time.sleep(1) #Timing
  295.     print("Please add a question, 4 choices, and a numercial answer.")
  296.     print("\n")
  297.     print("\n")
  298.     addQ()
  299.     print("Your question has been added")
  300.    
  301.  
  302.  
  303. #good bye message
  304. else:
  305.     print("""
  306.      _ _ _ _ _ _ _ _ _ _ _ _ _
  307.     |OFFo oON                  |
  308.     | .----------------------. |
  309.     | |  .----------------.  | |
  310.     | |  |                |  | |
  311.     | |))|                |  | |
  312.     | |  |   THANKS FOR   |  | |
  313.     | |  |    PLAYING!!   |  | |
  314.     | |  |                |  | |
  315.     | |  |                |  | |
  316.     | |  |                |  | |
  317.     | |  '----------------'  | |
  318.     | |__GAME BOY____________/ |
  319.     |          ________        |
  320.     |    .    (Nintendo)       |
  321.     |  _| |_   """"""""   .-.  |
  322.     |-[_   _]-       .-. (   ) |
  323.     |   |_|         (   ) '-'  |
  324.     |    '           '-'   A   |
  325.     |                 B        |
  326.     |          ___   ___       |
  327.     |         (___) (___)  ,., |
  328.     |        select start ;:;: |
  329.     |                    ,;:;' /
  330.     |                   ,:;:'.'
  331.     '-----------------------`
  332.  
  333. """)
  334. time.sleep(4) #Timing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement