Sep-06-2022, 02:42 AM
I just started learning how to code last week and tried making a random quiz program for one of my first projects and it's not working as intended. I assume the answer is simple, since I'm new and probably missing something super obvious.
A little embarrassing, but I've been trying to figure this out for 3 days! haha
The code at the moment isn't adding the score, nor is it giving the user the correct answer if answered wrong. Please help.
A little embarrassing, but I've been trying to figure this out for 3 days! haha
The code at the moment isn't adding the score, nor is it giving the user the correct answer if answered wrong. Please help.
import random def proper_answer(): while True: answer = int(input("> ")) if answer == 1 or answer == 2 or answer == 3: break else: print("Please enter a number from the answers available") print("Welcome to the Great Quiz Show Extravaganza!") print("You will be given 5 random questions to answer. Are you ready?") question_list = range(11) question_batch = random.sample(question_list, k=5) score = 0 answer = 0 for question in question_batch: if question == 1: print("In what year was the first-ever Wimbledon Championship held?\n1. 1877 \n2. 1888 \n3. 1890") # answer 1 proper_answer() if answer == 2 or answer == 3: print("I'm sorry, that's incorrect. The answer was 1877.") elif answer == 1: print("Good job. That's correct.") score += 1 answer = 0 if question == 2: print("Hg is the chemical symbol of which element?\n1. Cobalt \n2. Mercury \n3. Lithium") # answer 2 proper_answer() if answer == 1 or answer == 3: print("I'm sorry, that's incorrect. The answer was mercury.") elif answer == 2: print("Good job. That's correct.") score += 1 answer = 0 if question == 3: print("What is the capital city of Spain?\n1. Madrid \n2. Zaragoza \n3. Barcelona") # answer 1 proper_answer() if answer == 2 or answer == 3: print("I'm sorry, that's incorrect. The answer was Madrid.") elif answer == 1: print("Good job. That's correct.") score += 1 answer = 0 if question == 4: print("Which is the highest waterfall in the world?\n1. Yosemite Falls \n2. Iguazu Falls \n3. Angel Falls") # answer 3 proper_answer() if answer == 1 or answer == 2: print("I'm sorry, that's incorrect. The answer was Angel Falls.") elif answer == 3: print("Good job. That's correct.") score += 1 answer = 0 if question == 5: print("Which country invented tea?\n1. India \n2. China \n3. England") # answer 2 proper_answer() if answer == 1 or answer == 3: print("I'm sorry, that's incorrect. The answer was China.") elif answer == 2: print("Good job. That's correct.") score += 1 answer = 0 if question == 6: print("How long does it take to hard boil an egg?\n1. Six minutes \n2. Seven minutes \n3. Eight minutes") # answer 2 proper_answer() if answer == 1 or answer == 3: print("I'm sorry, that's incorrect. The answer was seven minutes.") elif answer == 2: print("Good job. That's correct.") score += 1 answer = 0 if question == 7: print("Name the world’s largest ocean.\n1. Pacific \n2. Atlantic \n3. Indian") # answer 1 proper_answer() if answer == 1 or answer == 2: print("I'm sorry, that's incorrect. The answer was Pacific.") elif answer == 1: print("Good job. That's correct.") score += 1 answer = 0 if question == 8: print("What color is a Himalayan poppy flower?\n1. Yellow \n2. Red \n3. Blue") # answer 3 proper_answer() if answer == 1 or answer == 2: print("I'm sorry, that's incorrect. The answer was blue.") elif answer == 3: print("Good job. That's correct.") score += 1 answer = 0 if question == 9: print("Which country did the band AC/DC originate in?\n1. America \n2. New Zealand \n3. Australia") # answer 3 proper_answer() if answer == 1 or answer == 2: print("I'm sorry, that's incorrect. The answer was Australia.") elif answer == 3: print("Good job. That's correct.") score += 1 answer = 0 if question == 10: print("When did the Cold War end?\n1. 1989 \n2. 1990 \n3. 1991") # answer 1 proper_answer() if answer == 2 or answer == 3: print("I'm sorry, that's incorrect. The answer was 1989.") elif answer == 1: print("Good job. That's correct.") score += 1 answer = 0 print(f"Your score is {score} out of 5!") if score == 5: print("Great job! You got the perfect score!") elif score == 0: print("You've got a lot of learning to do.") else: print("Good job! Though you've got some studying to do.")