Fairly new to python programming.
I'm writing a program for learning about US Presidents, the code works, but it is very rigid, I don't know how to add exceptions if the answer is wrong, but not technically wrong.
i.e. If the question is Who is the 32nd President? The user should be able to answer Franklin D. Roosevelt, or, Franklin Roosevelt, or FDR or just Roosevelt etc... The way my code is setup only allows for one answer, is there a way to add exceptions to where the user can get the answer right without having to answer exactly?
import random
def main():
presidents = {"first":"George Washington", "second":"John Adams","third":"Thomas Jefferson",
"fourth":"James Madison", "fifth":"James Monroe", "sixth":"John Quincy Adams",
"seventh":"Andrew Jackson", "eighth":"Martin Van Buren", "ninth":"William Henry Harrison",
"tenth":"John Tyler","eleventh":"James K. Polk", "twelth":"Zachary Taylor",}
wrong = []
print("President Test \n")
incorrect_answers = False
while len(presidents)>0:
pick=random.choice(list(presidents.keys()))
correct_answer=presidents.get(pick)
print("Who was the",pick,"President of the United States?"
answer=input("Your answer?: ")
if answer.lower()==correct_answer.lower():
print("That's Correct!\n")
del presidents[pick]
else:
print("That's Incorrect.")
print("The correct answer is", correct_answer)
wrong.append(pick)
incorrect_answers = True
Print("You missed", len(wrong), "Presidents.\n")
if incorrect_answers:
print("Here are the ones that you may want to brush up on:/n")
for each in wrong:
print(each)
else:
print("Perfect!")
main()
I was hoping that if I simply added an "or" statement in the list code that it would magically work, but I see that it doesn't.
"eleventh":"James K. Polk" or "James Polk"
Also hoping that it would be able to use more than 2 options,
"thirty fifth":"John F. Kennedy" or "John Kennedy" or "JFK"
Is there a way to do this with a list?
Thanks