-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathsQuiz.py
89 lines (67 loc) · 1.9 KB
/
MathsQuiz.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Maths Quiz
#
# Generates a maths quiz with 10 questions
# consisting of addition subtraction multiplication
# and division questions, each operator has
# different parameters for the values to make
# the questions reasonable
#
import random
difficulty = int()
difficultyQueue = []
#
# Generates the values for one question
# returns a question as a string and the answer as an integer
#
def getQuestion():
#
# Randomly selects an operator
#
randnum = random.randint(0, 3)
operator = ""
num1 = int()
num2 = int()
answer = int()
#
#
#
if randnum == 0:
operator = ("+")
num1 = random.randint(1, 100 + difficulty)
num2 = random.randint(1, 100 + difficulty)
elif randnum == 1:
operator = ("-")
num1 = random.randint(1, 100 + difficulty)
num2 = random.randint(1, 100 + difficulty)
if num1 < num2:
(num1, num2) = (num2, num1)
#subtract
elif randnum == 2:
#times
operator = ("*")
num1 = random.randint(1, 12 + round(difficulty /3))
num2 = random.randint(1, 12 + round(difficulty /3))
elif randnum == 3:
#divide
operator = ("/")
num2 = random.randint(1, 12 + round(difficulty /3))
answer = random.randint(1, 12 + round(difficulty /3))
num1 = num2 * answer
questionString = str(num1, operator, num2)
return questionString, answer
def runQuiz():
difficulty = (0)
correctCount = int(0)
for questionNo in range(1, 11):
genAnswer("Question", questionNo)
(Question, answer) = getQuestion(difficulty)
genAnswer(Question)
userInput = getAnswer()
if userInput.isnumeric():
if userInput == answer:
correctCount = (correctCount + 1)
else:
genAnswer("Answer must be a number")
class Quiz:
__init__()
runQuiz()