-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathmath-code-test-e.py
195 lines (162 loc) · 6.19 KB
/
math-code-test-e.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# Tests for Foundational Math Cert 5
def step00():
print("Code test passed")
print("Go on to the next step")
def step01():
print("Was your prediction correct? What is the next number in the sequence?")
print("Code test passed")
print("Go on to the next step")
def step02(code):
import re
print(" ")
# print(3+2*a, ", ", end=" ")
if re.search("print\(3\s*\+\s*2\*a\,\s*\"\,\s*\"\,\s*end\=\"\s*\"\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use print(3+2*a, \", \", end=\" \") in your code")
def step03(code):
import re
print(" ")
# print(3*2**a, ", ", end=" ")
if re.search("print\(3\*2\*\*a\,\s*\"\,\s*\"\,\s*end\=\"\s*\"\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use print(3*2**a, \", \", end=\" \") in your code")
def step04(code):
import re
print(" ")
code_count = 0
# next_number = a_list[n-1]*2+3
if re.search("next\_number\s*=\s*0", code):
print("Now just change the \'next_number = 0\' line")
elif re.search("next\_number\s*=\s*a\_list\[n\-1\]\s*\*2\s*\+\s*3", code):
print("Code test passed")
else:
print("You should use next_number = a_list[n-1]*2+3 in your code")
def step05(code):
import re
print(" ")
# fib[n-1] + fib[n-2]
if re.search("fib\[n\-1\]\s*\+\s*fib\[n\-2\]", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use fib[n-1] + fib[n-2] in your code")
def step06(code):
import re
print(" ")
code_count = 0
# for x in range(len(b_list)):
if re.search("range\(len\(b\_list\)\)\:", code):
code_count = code_count + 1
else:
print("You should use range(len(b_list)): in your code")
# plt.plot([x], [b_list[x]], 'bo')
if re.search("plt\.plot\(\[[a-z]\]\,\s*\[b\_list\[[a-z]\]\]\,", code):
code_count = code_count + 1
else:
print("You should use plt.plot([n], [b_list[n]], \'ro\') in your code")
if code_count==2:
print("Code test passed")
print("Go on to the next step")
def step07(code):
import re
print(" ")
# sum = sum + element
if sum==0:
print("Now update the sum variable in the loop")
elif re.search("sum\s*\=\s*sum\s*\+\s*element", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use sum = sum + element in your code")
def step08(code):
import re
print(" ")
if re.search("range\(11\)\:", code):
print("Now change the range to 42 and run this again")
elif re.search("range\(42\)\:", code):
print("Now change the range to 100 and run this again")
if re.search("range\(100\)\:", code):
print("Code test passed")
print("Go on to the next step")
def step09(code):
import re
print(" ")
# print(math.factorial(number),
if re.search("print\(number\,\s*\"\!\s*\=\s*\"\)", code):
print("Now change the first print statement to include math.factorial()")
elif re.search("print\(number\,\s*\"\!\s*\=\s*\"\,\s*math\.factorial\(number\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use print(number, \"! = \", math.factorial(number)) in your code")
def step10(code):
import re
print(" ")
# for a in range(11):
if re.search("for a in range\(11\)\:", code):
print("Now change the range to be 100")
elif re.search("for a in range\(100\)\:", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use for a in range(100): in your code")
def step11(code):
import re
print(" ")
# probability = correct/possible
if re.search("probability\s*\=\s*correct\/possible", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use probability = correct/possible in your code")
def step12(code):
import re
print(" ")
if re.search("combined\_prob\s*\=\s*0", code):
print("Now change the combined_prob line")
elif re.search("combined\_prob\s*\=\s*prob\*prob\*prob\*prob", code):
print("Code test passed")
print("Go on to the next step")
elif re.search("combined\_prob\s*\=\s*prob\*\*4", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use combined_prob = prob**4 in your code")
def step13(code):
import re
print(" ")
if re.search("combined\_prob\s*\=\s*0", code):
print("Now change the combined_prob line")
elif re.search("combined\_prob\s*\=\s*prob\s*\+\s*prob\s*\+\s*prob", code):
print("Code test passed")
print("Go on to the next step")
elif re.search("combined\_prob\s*\=\s*prob\s*\*3", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use combined_prob = prob + prob + prob in your code")
def step14(code):
import re
print(" ")
# starters = math.factorial(n)/(math.factorial(r)*math.factorial(n-r))
if re.search("starters\s*\=\s*0", code):
print("Now change the starters = 0 line")
elif re.search("starters\s*\=\s*math\.factorial\(n\)\/\(math\.factorial\(r\)\*math\.factorial\(n\s*\-\s*r\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use starters = math.factorial(n)/(math.factorial(r)*math.factorial(n-r)) in your code")
def step15(code):
import re
print(" ")
# arr = math.factorial(n)/math.factorial(n-r)
if re.search("arr\s*\=\s*0", code):
print("Now change the arr = 0 line")
elif re.search("arr\s*\=\s*math\.factorial\(n\)\/math\.factorial\(n\s*\-\s*r\)", code):
print("Code test passed")
else:
print("You should use arr = math.factorial(n)/math.factorial(n-r) in your code")