So i want to be able to make a multiple choice quiz program using dictionaries. I have one dictionary with all the questions as the key and the answer as a value and a second dictionary thats empty. I want to append all of the incorrect questions someone may have into the empty dictionary. i want to do this in order to allow users to retake the exam but only with the questions that they answered wrong. Yet i cannot find a way to append a key and value from one list to another without being specific.
Here is my code below:
def intro():
print("Hello and welcome to the random questions test")
global name
name = input("what is your name? " + "\n" + "\n")
if name == "":
print("Enter a valid name!")
name = input("what is your name? " + "\n" + "\n")
else:
ans2 = input("\n" + "Hello " + name + " Are you sure you want to take the exam? (yes/no)" + "\n" + "\n")
if ans2 == "no":
print("\n" + "aw man, until next time " + name + "!" + "\n")
elif ans2 == "yes":
print("\n" + "Okay!" + "\n")
Quiz()
def Quiz():
q1 = """Who holds the NFL record for the most receiving yards in a single game?
a. Calvin Johnson
b. Deandre Hopkins
c. Flipper Anderson
d. Jerry Rice"""
q2 = """In what year was the eiffel tower built?
a. 1492
b. 1889
c. 2013
d. 1766"""
q3 = """How many countries are in the world today?
a. 205
b. 195
c. 673
d. 142"""
q4 = """Who is the CEO of apple currently (2020)?
a. Tim Cook
b. Sergio Kitchens
c. Daniel Johnson
d. Steve Jobs"""
q5 = """who is the 23rd president of the united states?
a. Grover Cleveland
b. Andrew Jackson
c. Anderson Berkshire
d. Benjamin Harrison"""
q6 = """X + 5x - 10 = 500... What does X equal?
a. 85
b. 84
c. 102
d. 0"""
q7 = """Who is currently the richest person on earth?
a. Tim Cook
b. Jeff Bezos
c. Bill Gates
d. Bill Nye"""
q8 = """When was Howard University Established?
a. May 4, 2002
b. March 5, 1855
c. September 1, 1844
d. March 2, 1867"""
q9 = """What can you catch but not throw?
a. A football
b. A conversation
c. A cold
d. A tennis ball in the Appalachian Mountains"""
q10 = """Which country is responsible for the production of 95% of the worlds opal stones?
a. Brazil
b. Mexico
c. Honduras
d. Austrailia"""
q11 = """How many species of Toothed and Baleen whales exist?
a. 14 and 2
b. 76 and 14
c. 5 and 10
d. 75,000"""
q12 = """Who holds the world record for the most chicken nuggets eaten in 1 hour?
a. Naader Reda
b. Nicolo Reda
c. Stefano Neder
d. Josh Jacobs"""
q13 = """Who invented the bessemer process?
a. Henry Bessemer
b. Markus Bessemer
c. Bessemer Robinson
d. Anakin Skywalker"""
q14 = """When was Mortal Kombat 6 released?
a. April 1, 2002
b. August 15, 2007
c. October 4, 2004
d. December 25, 2006"""
q15 = """In which City located in the USA is it illegal to say "Oh, boy"?
a. Denver, Colorado
b. Lexington, Kentucky
c. Jonesboro, Georgia
d. Wilbur, Washington"""
Questions = {q1: 'c', q2: 'b', q3: 'b', q4: 'a', q5: 'd', q6: 'a', q7: 'b', q8: 'd', q9: 'c', q10: 'd', q11: 'b', q12: 'a', q13: 'a', q14: 'c', q15: 'c' }
inc_questions = {}
score = 0
for q in Questions:
print(q)
ans = input("> ")
if ans.lower() == Questions[q]:
print("\n" + "Correct!" + "\n")
score += 1
else:
print("\n" + "Incorrect!" + "\n")
for q, a in Questions.items():
if ans.lower() != Questions[q]:
inc_questions[q] = a
if score == 15:
print("Congratulations " + name + ", you scored a perfect 15/15!")
elif score < 15 and score > 11:
print("Good job " + name + "! you got " + str(score) + " out of 15 correct!")
print("\n" + "Would you like to re-answer the questions that were incorrect?" + "\n")
elif score < 12 and score > 8:
print("You did pretty well " + name + ", you got " + str(score) + " out of 15 correct!")
print("\n" + "Would you like to re-answer the questions that were incorrect?" + "\n")
elif score < 9 and score > 5:
print("Unfortunately " + name + " you did not pass, you got " + str(score) + " out of 15 correct!")
print("\n" + "Would you like to re-answer the questions that were incorrect?" + "\n")
elif score < 6 and score > 0:
print("Jeez " + name + " you did awful lol, you got " + str(score) + " out of 15 correct!")
print("\n" + "Would you like to re-answer the questions that were incorrect?" + "\n")
elif score == 0:
print("Oh lord " + name +" you need some serious help you got nothing right!")
print("\n" + "Would you like a retake?" + "\n")
print(inc_questions)
intro()