Quiz using list
QandA = [
"1. What is the most common element on Earth?" , "oxygen" ,
"2. What is the planet closest to our Sun?" , "mercury" ,
"3. What is the smallest planet in our solar system?" , "mercury"
]
points = 0
current = 0
questions = 3
print ("Welcome to my simple quiz")
question1 = input (QandA[current])
print(QandA[0])
if question1 == QandA[current + 1]:
print (question1 + " is correct!\n")
current += 2
points += 1
else:
print(question1 + " is incorrect :(\n")
current += 2
question2 = input (QandA[current])
print(QandA[2])
if question2 == QandA[current + 1]:
print (question2 + " is correct!\n")
current += 2
points += 1
else:
print(question2 + " is incorrect :(\n")
current += 2
question3 = input (QandA[current])
print(QandA[4])
if question3 == QandA[current + 1]:
print (question3 + " is correct!\n")
current += 2
points += 1
else:
print(question3 + " is incorrect :(\n")
current += 2
# If statements not efficient at all. The code does not iterate therefore is not smart
print("Well done, you scored " + str(points) +"/" + str(questions))
QandA = [
"1. What is the most common element on Earth?" , "oxygen" ,
"2. What is the planet closest to our Sun?" , "mercury" ,
"3. What is the smallest planet in our solar system?" , "mercury"
]
points = 0
current = 0
questions = 1
print ("Welcome to my simple quiz")
while questions < 4:
question = input (QandA[current]) # sets the question variable to the "current" index from the dictionary
if question == QandA[current + 1]: # "current + 1" represents the answer
print(QandA[current]) # print the question first
print (question + " is correct! \n")
current += 2
points += 1
else:
print(QandA[current])
print(question + " is incorrect :( \n")
current += 2
questions = questions + 1
print("Well done, you scored " + str(points) +"/" + str(questions-1))