Aug-14-2020, 02:17 AM
Hi, so for school I had to make a multiple choice game. I was wondering if this program that ive created would be get a good mark. It is graded on the proper usage of for loops and if statements. (just the basics). I also added the usage of a class. Although I don't know if that will help. If you guys have any pointers to make my code more compact or efficient, due tell. Thanks!
import time # list of prompts prompts = [ "What is the color of an apple? \n(a) red \n(b) blue \n(c) purple", "What is the color of an banana? \n(a) green \n(b) yellow \n(c) orange", "What is the color of an strawberry? \n(a) red \n(b) blue \n(c) green", ] # question class class Questions: def __init__(self, prompt, answer): self.prompt = prompt self.answer = answer questions = [Questions(prompts[0], "a"), Questions(prompts[1], "b"), Questions(prompts[2], "a"), ] score = 0 # main loop for item in questions: print(item.prompt) answer = input("Insert your answer: ") if answer == item.answer: # check if input corresponds with the answer assigned to each prompt. print("\nYou got it correct!\n") score += 1 else: print("\nYou got it wrong!\n") ask = True print(f"You got {score}/3 correct!") # ask the user if he wants to close the game if ask: answer = input("Do you want to continue? \n yes \n no \n") if answer == "n" or answer == "No" or answer == "no": print("Thank you for playing!") time.sleep(1)