Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This program will give a user the option to select a category
- #From that category, the user will be asked a series of questions
- #The user is awarded 1 point for each correct answer
- #If the user scores 5 points, they are able to create a question
- #The user has a "cheat" if you select 5, you auto pass and get a point
- #if the user chooses 5 and already used the cheat, they will -1 point.
- # This is the orginal list for the questions
- sci =[{"question":"How old is the earth?",
- "choice":["1. 4.8 BYO.","2. 5.5 BYO.","3. 6,000 years.",
- "4. 65 MYO."],"answer":1},
- {"question":"What planet is closest in size to our moon?",
- "choice":["1. Venus","2. Mercury",
- "3. Jupiter","4. Pluto"],"answer":2},
- {"question":"What's the base unit of mass in the metric system?", #questions for science category
- "choice":["1. Pounds","2. Liters",
- "3.Jouls","4. Kilograms"],"answer":4},
- {"question":"What energy unit is defined as the heat required to raise one kilogram of water by one degree Celsius?",
- "choice":["1. One Calorie.","2.One KCalorie",
- "3.One Joul","4. One Degree F"],"answer":1},
- {"question":"What's the most malleable metal?",
- "choice":["1. Silver","2. Gold",
- "3. Copper","4. Steel"],"answer":2}]
- import sys
- import time
- from guestionGivefunc import addQ,sciquestionAsk,popquestionAsk
- import pickle
- sciIn = open('sciList.txt','rb')
- sci = pickle.load(sciIn)
- def addQ():
- dicQ = {}
- userChoice=[]
- userCat = int(input("Please select which category you would like to add too. "))
- question = input("Please type your question: ")
- dicQ["question"] = question
- userChoice.append(input("please type choice 1. "))
- userChoice.append(input("please type choice 2. "))
- userChoice.append(input("please type choice 3. ")) #This function is to create a question to add if you achive a perfect score
- userChoice.append(input("please type choice 4. "))
- dicQ["choice"]= userChoice
- answer = int(input("Type the answer 1-4: " ))
- dicQ["answer"]= answer
- if userCat == 1:
- sciOut = open("sciList.txt",'wb')
- sci.append(dicQ)
- pickle.dump(sci, sciOut)
- sciOut.close()
- elif userCat == 2:
- pop.append(dicQ)
- def sciquestionAsk():
- global points
- count = 0
- cheat = 1
- while count < len(sci):
- print(sci[count]['question'])
- time.sleep(.5)#Timing
- print("\n") #pulls count and question down the list of dicts
- print("\n")
- print(sci[count]['choice']) #prints the choices to choose from
- time.sleep(.5)
- print("\n")
- print("\n")
- answer = int(input("Please select your choice: "))
- print("\n")
- print("\n")
- if sci[count]["answer"]==answer:
- print("\n")
- time.sleep(.5) #Timing
- print("\n") #Checks to see if correct answer was givin and awards points
- print("""
- __________________________________________________
- I I
- I THAT IS CORRECT!! I
- I I
- I 1 POINT! I
- I I
- __________________________________________________
- """)
- print("\n")
- print("\n")
- points += 1
- print("You earned 1 points!")
- time.sleep(1) #Timing
- print("\n")
- print("\n")
- print("You now have ",points,"points!")
- elif answer == 5 and cheat == 1:#This section adds the cheat option of "5"
- print("You used your cheat")
- cheat -= 1
- points += 1
- elif answer == 5 and cheat != 1: #This is what happens if they try to cheat and fail
- print("You do not have a cheat.")
- print("Therefore your answer is incorrect.")
- print("Cheaters shall be punished. -1 points")
- points -= 1
- print("You now have,",points,"points.")
- else: #this is the incorrect message, displays points and shows correct answer
- print("""
- __________________________________________________
- I I
- I THAT IS INCORRECT!! I
- I I
- I 0 POINTs I
- I I
- __________________________________________________
- """)
- print("The correct answer was",sci[count]["answer"])
- time.sleep(.5) #Timing
- print("You have ",points, "points.")
- count+=1
- print("\n")
- print("\n")
- def popquestionAsk():
- count=0
- global points
- cheat = 1
- while count < len(pop):
- print(pop[count]['question'])
- time.sleep(.5) #Timing
- print("\n")
- print("\n")
- print(pop[count]['choice'])
- time.sleep(.5) #Timing
- print("\n")
- print("\n")
- answer = int(input("Please select your choice: "))
- time.sleep(.5) #Timing
- print("\n")
- print("\n")
- if pop[count]["answer"]==answer:
- print("\n")
- print("\n")
- print("""
- __________________________________________________
- I I
- I THAT IS CORRECT!! I
- I I
- I 1 POINT! I
- I I
- __________________________________________________
- """)
- print("\n")
- print("\n")
- points+=1
- print("You earned 1 point!")
- time.sleep(.5) #Timing
- print("\n")
- print("\n")
- print("You now have, ",points,"points!")
- elif answer == 5 and cheat == 1:#This section adds the cheat option of "5"
- print("You used your cheat, and gained a point!")
- print("\n")
- print("\n")
- cheat -= 1
- points += 1
- elif answer == 5 and cheat != 1: #This is what happens if they try to cheat and fail
- print("You do not have a cheat.")
- print("Therefore your answer is incorrect.")
- print("Cheaters shall be punished. -1 points")
- points -= 1
- print("You now have,",points,"points.")
- else:
- print("""
- __________________________________________________
- I I
- I THAT IS INCORRECT!! I
- I I
- I 0 POINTS I
- I I
- __________________________________________________
- """)
- print("The correct answer was",pop[count]["answer"])
- time.sleep(.5) #Timing
- print("You have ",points, "points.")
- count=count + 1
- pop =[
- {"question":"Complete this lyric:“We don’t care, we’re driving ________in our dreams.”?",
- "choice":["1. Vespas.","2. Cadillacs.",
- "3. Golf Balls.","4.The Enterprise."],"answer":2.},
- {"question":"Which pop star was named after a professional wrestler?",
- "choice":["1.Psy.","2.Lorde.",
- "3. Bruno Mars.","4. Justin 'The Hulk' Bieber."],"answer":3}, #questions for pop culture category
- {"question":"The quote 'It's a trap!' comes from this...?",
- "choice":["1. Half-Life.","2. Star Wars.",
- "3. Star Trek.","4. Space Balls."],"answer":2},
- {"question":"Avengers, X-Men and Spider-man are all set in this univese named after the comic books...?",
- "choice":["1. DC.","2. Dark Horse.",
- "3. Marvel.","4. Action Comics."],"answer":3},
- {"question":"Which of the following TV shows is a spin-off of the mega-hit show 'Breaking Bad'?",
- "choice":["1. Better Call Saul.","2. Battle Creek.",
- "3. Breakfast with Jr.","4. Jesse and James."],"answer":1}
- ]
- global points
- points = 0
- #starts count to run though category list
- print("\n") #intro pssst, for a cheat, try using option 5
- print("""
- _________Welcome to the TRIVIA CHALLENGE!_________
- I I
- I Choose a Category! I
- I I
- I 1.Science 2.Pop Culture I
- I I
- __________________________________________________
- """)
- print("\n")
- print("\n")
- time.sleep(.5)#Timing
- cat = int(input("What Category would you like? "))
- print("\n")
- print("\n")
- #Starts the question process depending on the category selected
- if cat == 1:
- sciIn.close()
- sciquestionAsk()
- if cat == 2: #same as cat 1 with pop replacing sci
- popquestionAsk()
- if points > 4: #This begins the process to add a question. You must have gotten 5 points to access this screen.
- print("""
- __________________________________________________
- I CONGRATULATIONS!!! I
- I I
- I I
- I YOU CAN NOW ADD A QUESTION! I
- I I
- I Choose 1 for Science I
- I Choose 2 for Pop Culture I
- I I
- I I
- __________________________________________________
- """)
- time.sleep(1) #Timing
- print("Please add a question, 4 choices, and a numercial answer.")
- print("\n")
- print("\n")
- addQ()
- print("Your question has been added")
- #good bye message
- else:
- print("""
- _ _ _ _ _ _ _ _ _ _ _ _ _
- |OFFo oON |
- | .----------------------. |
- | | .----------------. | |
- | | | | | |
- | |))| | | |
- | | | THANKS FOR | | |
- | | | PLAYING!! | | |
- | | | | | |
- | | | | | |
- | | | | | |
- | | '----------------' | |
- | |__GAME BOY____________/ |
- | ________ |
- | . (Nintendo) |
- | _| |_ """""""" .-. |
- |-[_ _]- .-. ( ) |
- | |_| ( ) '-' |
- | ' '-' A |
- | B |
- | ___ ___ |
- | (___) (___) ,., |
- | select start ;:;: |
- | ,;:;' /
- | ,:;:'.'
- '-----------------------`
- """)
- time.sleep(4) #Timing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement