-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathmath-code-test-d.py
364 lines (286 loc) · 10.8 KB
/
math-code-test-d.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# Tests for Foundational Math Cert 4
def step00():
print("Code test passed")
print("Go on to the next step")
def step01(code):
import re
print(" ")
# verts = [(0., 0.), (0., 2.), (2., 2.), (2., 0.), (0., 0.),]
# verts = [(0., 0.), (-1., 1.), (0., 2.), (2., 2.), (3., 1.), (2., 0.), (0., 0.),]
if re.search("verts\s*\=\s*\[\(0\.\,\s*0\.\)\,\s*\(0\.\,\s*2\.\)\,\s*\(2\.\,\s*2\.\)\,\s*\(2\.\,\s*0\.\)\,\s*\(0\.\,\s*0\.\)\,\s*\]", code):
print("Now change the code and run it again.")
elif re.search("verts\s*\=\s*\[\(0\.\,\s*0\.\)\,\s*\(\-1\.\,\s*1\.\)\,\s*\(0\.\,\s*2\.\)\,\s*\(2\.\,\s*2\.\)\,\s*\(3\.\,\s*1\.\)\,\s*\(2\.\,\s*0\.\)\,\s*\(0\.\,\s*0\.\)\,\s*\]", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use verts = [(0., 0.), (-1., 1.), (0., 2.), (2., 2.), (3., 1.), (2., 0.), (0., 0.),] in your code")
def step02(code):
import re
print(" ")
code_count = 0
# input
if re.search("c\_string\s*=\s*input\(\"Side\s*c\s*=\s*\"\)", code):
code_count = code_count + 1
else:
print("You should use c_string = input(\"Side c = \") in your code")
# if
if re.search("if\s*\(c\_string\s*\=\=\s*\"c\"\)\:", code):
code_count = code_count + 1
else:
print("You should use if (c_string==\"c\"): in your code")
# formula
if re.search("c\s*=\s*math\.sqrt\(a\*\*2\s*\+\s*b\*\*2\)", code):
code_count = code_count + 1
else:
print("You should use c = math.sqrt(a**2 + b**2) in your code")
# print
if re.search("print\(\"c\s*=\s*\"\,\s*c\)", code):
code_count = code_count + 1
else:
print("You should use print(\"c = \", c) in your code")
# code count
if code_count==4:
print("Code test passed")
print("Go on to the next step")
def step03():
print("Notice how the distance is the hypotenuse")
print("Go on to the next step")
def step04(code):
import re
print(" ")
code_count = 0
# x2 = float(second[0])
if re.search("x2\s*\=\s*float\(second\[0\]\)", code):
code_count = code_count + 1
else:
print("You should use x2 = float(second[0]) in your code")
# y2 = float(second[1])
if re.search("y2\s*\=\s*float\(second\[1\]\)", code):
code_count = code_count + 1
else:
print("You should use y2 = float(second[1]) in your code")
# distance = math.sqrt((x2-x1)**2 + (y2-y1)**2)
if re.search("distance\s*\=\s*math\.sqrt\(\(x2\-x1\)\*\*2\s*\+\s*\(y2\-y1\)\*\*2\)", code):
code_count = code_count + 1
else:
print("You should use distance = math.sqrt((x2-x1)**2 + (y2-y1)**2) in your code")
# code count
if code_count==3:
print("Code test passed")
print("Go on to the next step")
def step05(code):
import re
print(" ")
code_count = 0
# x = (x1+x2)/2
if re.search("x\s*\=\s*\(x1\s*\+\s*x2\)\/2", code):
code_count = code_count + 1
else:
print("You should use x = (x1+x2)/2 in your code")
# y = (y1+y2)/2
if re.search("y\s*\=\s*\(y1\s*\+\s*y2\)\/2", code):
code_count = code_count + 1
else:
print("You should use y = (y1+y2)/2 in your code")
# code count
if code_count==2:
print("Code test passed")
print("Go on to the next step")
def step06():
print("Notice the description of each side")
print("Go on to the next step")
def step07():
print("Notice how the description of each side changed")
print("Go on to the next step")
def step08():
print("Notice the different ratios for A and B")
print("Go on to the next step")
def step09(code):
import re
print(" ")
code_count = 0
if re.search("sinA\s*\=\s*opp\/hyp", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use sinA = opp/hyp in your code")
def step10():
print(" ")
print("Notice the different ratios for A and B")
print("Go on to the next step")
def step11(code):
import re
print(" ")
code_count = 0
if re.search("cosA\s*\=\s*adj\/hyp", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use cosA = adj/hyp in your code")
def step12():
print(" ")
print("Notice the different ratios for A and B")
print("Go on to the next step")
def step13(code):
import re
print(" ")
if re.search("tanA\s*\=\s*opp\/adj", code):
print("Code test passed")
print("Go to the next step")
else:
print("You should use tanA = opp/adj in your code")
def step14(code):
import re
print(" ")
code_count = 0
# cosA_actual = round(b/c,4)
if re.search("cosA\_actual\s*\=\s*round\(b\/c\,\s*4\)", code):
code_count = code_count + 1
else:
print("You should use cosA_actual = round(b/c,4) in your code")
# tanA_actual = round(a/b,4)
if re.search("tanA\_actual\s*\=\s*round\(a\/b\,\s*4\)", code):
code_count = code_count + 1
else:
print("You should use tanA_actual = round(a/b,4) in your code")
# sinB_actual = round(b/c,4)
if re.search("sinB\_actual\s*\=\s*round\(b\/c\,\s*4\)", code):
code_count = code_count + 1
else:
print("You should use sinB_actual = round(b/c,4) in your code")
# cosB_actual = round(a/c,4)
if re.search("cosB\_actual\s*\=\s*round\(a\/c\,\s*4\)", code):
code_count = code_count + 1
else:
print("You should use cosB_actual = round(a/c,4) in your code")
# tanB_actual = round(b/a,4)
if re.search("tanB\_actual\s*\=\s*round\(b\/a\,\s*4\)", code):
code_count = code_count + 1
else:
print("You should use tanB_actual = round(b/a,4) in your code")
if code_count==5:
print("Code test passed")
print("Go to the next step")
def step15(code):
import re
print(" ")
code_count = 0
if re.search("round\(math\.cos\(math\.radians\(angle\)", code):
print("Code test passed")
print("Go to the next step")
else:
print("Your code should include ratio_c = round(math.cos(math.radians(angle)),4)")
# step 16 re-uses step 00
def step17():
print(" ")
print("Look at the triangle and notice the pattern")
print("Go to the next step")
print(" ")
def step18():
print("See how the sin() and cos() relate to points on the circle")
print("Go on to the next step")
def step19(code):
import re
print(" ")
code_count = 0
# cos_value
if re.search("cos\_value\s*\=\s*0", code):
print("Scroll up to see the example, then write the code to solve for b")
elif re.search("\=\s*round\(math\.cos\(math\.radians\(rangle\)\)\,\s*4\)", code):
code_count = code_count + 1
else:
print("Your code should include cos_value = round(math.cos(math.radians(rangle)), 4)")
# side_b
if re.search("side\_b\s*\=\s*0", code):
print(" ")
elif re.search("side\_b\s*\=\s*round\(sideC\*cos\_value\,2\)", code):
code_count = code_count + 1
else:
print("Your code should include side_b = round(sideC*cos_value,2)")
if code_count==2:
print("Code test passed")
print("Go on to the next step")
def step20(code):
import re
print(" ")
code_count = 0
# sideA/math.sin(radian_angle)
if re.search("sideC\s*=\s*0", code):
print("Now write the code to solve for sideC")
elif re.search("sideA\/math\.sin\(radian\_angle\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include sideC = sideA/math.sin(radian_angle)")
def step21(code):
import re
print(" ")
code_count = 0
# sideA/math.cos(radian_angle)
if re.search("sideC\s*=\s*0", code):
print("Now write the code to solve for the diagonal force")
elif re.search("sideA\/math\.cos\(radian\_angle\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include sideC = sideA/math.cos(radian_angle)")
def step22(code):
import re
print(" ")
code_count = 0
# sideA/math.tan(radian_angle)
if re.search("sideB\s*=\s*0", code):
print("Now write the code to solve for the distance")
print(" ")
elif re.search("sideA\/math\.tan\(radian\_angle\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include sideC = sideA/math.cos(radian_angle)")
def step23(code):
import re
print(" ")
code_count = 0
# side_B = math.sin(math.radians(angle_B))*sideA/math.sin(math.radians(angleA))
if re.search("sideB\s*=\s*0", code):
print("Now write the code to solve for side b")
print(" ")
elif re.search("side\_B\s*\=\s*math\.sin\(math\.radians\(angle\_B\)\)\*sideA\/math\.sin\(math\.radians\(angleA\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include side_B = math.sin(math.radians(angle_B))*sideA/math.sin(math.radians(angleA))")
def step24(code):
import re
print(" ")
code_count = 0
# almost = sideA**2 + sideB**2 - 2*sideA*sideB*math.cos(math.radians(angle_C))
# side_C = math.sqrt(almost)
if re.search("sideC\s*=\s*0", code):
print("Now write the code to solve for side c")
print(" ")
elif re.search("sideA\*\*2\s*\+\s*sideB\*\*2\s*\-\s*2\*sideA\*sideB\*math\.cos\(math\.radians\(angle\_C\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include side_C = math.sqrt(sideA**2 + sideB**2 - 2*sideA*sideB*math.cos(math.radians(angle_C)))")
def step25(code):
import re
print(" ")
code_count = 0
# area = 0.5*sideA*sideB*math.sin(math.radians(angleC))
if re.search("area\s*=\s*0", code):
print("Now write the code to find the area")
print(" ")
elif re.search("area\s*\=\s*0\.5\*sideA\*sideB\*math\.sin\(math\.radians\(angleC\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include area = 0.5*sideA*sideB*math.sin(math.radians(angleC))")
# no test for step 26
def step27():
print("Notice the pattern, then go on to the next step")
print(" ")
# no test for step 28
def step29():
print("Notice which frequency combinations produce more regular patterns \n")