159k views
4 votes
15 points simple python code

Using a true/false format, make a 4 question quiz, where the user can type in “True” or “False” for their answers. Accept True and true or False and false as valid answers. Anything that is not one of those 4 words is automatically incorrect.

After each question, inform the user whether they got the answer right or wrong (correct or incorrect).

You will need to not only report whether each question is right or wrong, but also keep track of their score throughout the program. At the end of the 4 questions quiz, output the score in percent to the user so they know how well they did.

1 Answer

1 vote

Answer:

Step-by-step explanation:

# Quiz questions and answers

questions = [

"Is the earth round? (True or False)",

"Is the sun a planet? (True or False)",

"Is the capital of USA New York? (True or False)",

"Is water a solid? (True or False)"

]

answers = [False, False, False, False]

# Initialize score

score = 0

# Ask questions and check answers

for i in range(len(questions)):

answer = input(questions[i]).lower()

if answer == "true":

answer = True

elif answer == "false":

answer = False

else:

answer = None

if answer == answers[i]:

score += 1

elif answer is None:

print("Invalid answer")

else:

print("Incorrect")

# Print final score

print("Your score is:", score)

User Andy Rose
by
8.5k points

No related questions found