First of all, I'm a total newbie when it comes to Python so feel free to correct me.
I'm having trouble with a quiz im making for a school project, I've been searching the internet for help without any luck so I decided to ask you guys to help me solve it.
The quiz will contain 10 different questions, and I want them to be selected randomly from my list until user decides to quit. Every time the user answer a question I want them to input "yes or no" to continue, if the answer yes another question pops up. If no the game quits and they will see their total score( in percent), if the score is below 60% they failed the test.
So please , any tips or directions are welcome!
Here's an example of the code I have so far(Python 3):
import random
questions = ["q1" etc..]
answers = ["a1" etc..]
print ("Hello and welcome to my quiz!")
print ("======================================")
input("Press enter to continue.")
print("")
print ("Let's begin!")
print (" ")
question = random.sample(range(1, len(questions) + 1), len(questions))
for num in question:
if num == 1:
user_answer_1 = input(questions[0])
if user_answer_1.lower() == answers[0]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 2:
user_answer_2 = input(questions[1])
if user_answer_2.lower() == answers[1]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 3:
user_answer_3 = input(questions[2])
if user_answer_3.lower() == answers[2]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 4:
user_answer_4 = input(questions[3])
if user_answer_4.lower() == answers[3]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 5:
user_answer_5 = input(questions[4])
if user_answer_5.lower() == answers[4]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 6:
user_answer_6 = input(questions[5])
if user_answer_6.lower() == answers[5]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 7:
user_answer_7 = input(questions[6])
if user_answer_7.lower() == answers[6]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 8:
user_answer_8 = input(questions[7])
if user_answer_8.lower() == answers[7]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 9:
user_answer_9 = input(questions[8])
if user_answer_9.lower() == answers[8]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
if num == 10:
user_answer_10 = input(questions[9])
if user_answer_10.lower() == answers[9]:
print("Correct\n")
score = score + 1
else:
print("Incorrect\n")
print ("Your totalt score is:",(score)
Aucun commentaire:
Enregistrer un commentaire