-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.py
61 lines (48 loc) · 1.49 KB
/
quiz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Quiz Program
# Questions
# Austen Calzadilla
# Jessica Rex
import question
# Quiz Logic
num_questions = question.num_questions
max_attempts = 2
questions_right = 0
questions_wrong = 0
# Print question and possible answers
def printQuestion(q):
print("{0}. {1}".format(q.questionNum, q.question))
print(" {0}".format(q.a1))
print(" {0}".format(q.a2))
print(" {0}".format(q.a3))
print(" {0}".format(q.a4))
# Get answer from user
def getAnswer(q):
q.attemptCount += 1
answer = raw_input("Answer: ")
return answer
# Start quiz loop
for index in range(num_questions):
current_q = question.questions[index]
printQuestion(current_q)
done = 0
while not done:
answer = getAnswer(current_q)
if(answer == current_q.rightAns):
print("Correct!\n")
current_q.complete = 1
done = 1
else:
current_q.wrongCount += 1
if current_q.wrongCount >= 2:
print("Sorry, you have exceeded the max attempts.\n" +
"The correct answer is: {0}\n".format(current_q.rightAns))
done = 1
else:
print("Incorrect... try again\n")
attempts = correct = wrong = 0
for q in question.questions:
correct += q.complete
wrong += q.wrongCount
attempts += q.complete + q.wrongCount
print("Attempts: {0}".format(attempts))
print("Correct: {0} --- Wrong: {1}".format(correct, wrong))