Python Forum
Assignment to make a multiple choice game - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Assignment to make a multiple choice game (/thread-29013.html)



Assignment to make a multiple choice game - blacklight - Aug-14-2020

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)

    



RE: Assignment to make a multiple choice game - Larz60+ - Aug-14-2020

I'd give you a good grade.