-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathmath-code-test-a.py
346 lines (277 loc) · 9.21 KB
/
math-code-test-a.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
# Tests for Foundational Math Cert 1
def step01(code):
import re
print(" ")
if re.search("print\s*\(\s*a\s*\+\s*b\s*\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use print(a + b) in your code")
def step02(code):
import re
print(" ")
if re.search("print\s*\(\s*c\s*\-\s*d\s*\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use print(c - d) in your code")
def step03(code):
import re
print(" ")
if re.search("print\s*\(\s*[e]\s*\*\s*[f]\s*\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use print(e * f) in your code")
def step04(code):
import re
print(" ")
if re.search("print\s*\(\s*[g]\s*\/\s*[h]\s*\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use print(g/h) in your code")
def step05(code):
import re
print(" ")
if re.search("intB\s*\=\s*int\(strB\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use intB = int(strB) in your code")
def step06(code):
import re
print(" ")
#intA = int(input('Enter an integer: '))
if re.search("intB\s*\=\s*int\(input\(\'Enter an integer\:\s*\'\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use intB = int(input('Enter an integer: ')) in your code")
def step07(code):
import re
print(" ")
#b = float(input('Enter a number: '))
if re.search("b\s*\=\s*float\(input\(\'Enter a number\:\s*\'\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use b = float(input('Enter a number: ')) in your code")
def step08(answer):
print(" ")
if answer==8:
print("Code test passed")
print("Go on to the next step")
else:
print("You can try again if you like")
def step09(code):
import re
print(" ")
# print(a%b)
if re.search("print\(a\s*\%\s*b\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use print(a % b) in your code")
def step10(code):
import re
print(" ")
if re.search("if number\s*\%\s*test\_factor\s*\=\=\s*0\:", code):
print("Code test passed")
print("Go on to the next step")
else:
print("You should use if number % test_factor == 0: in your code")
def step11(code):
import re
print(" ")
if re.search("if number\s*\%\s*test\_factor\s*\=\=\s*0:", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include if number % test_factor == 0:")
def step12(code):
import re
print(" ")
if re.search("if test\_number\:", code):
print("Now change the if statement")
elif re.search("if number\s*\%\s*test\_number\=\=0\:", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include if number % test_number == 0:")
def step13(code):
import re
print(" ")
if re.search("print\(1\/n\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include print(1/n)")
def step14(code):
import re
print(" ")
if re.search("b\s*=\s*float\(sp\[1\]\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include b = float(sp[1])")
def step15(code):
import re
print(" ")
if re.search("print\(n\*\*2\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include print(n**2)")
def step16(code):
import re
print(" ")
if re.search("print\(math\.sqrt\(n\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include print(math.sqrt(n))")
def step17(code):
import re
print(" ")
if re.search("print\(math\.floor\(n\)\)", code):
print("Code test passed")
print("Go on to the next step")
else:
print("Your code should include print(math.floor(n))")
def step18(code):
import re
print(" ")
code_count=0
# if n % (maybe_factor**2) == 0:
if re.search("if n\s*\%\s*\(maybe\_factor\*\*2\)\s*\=\=\s*0\:", code):
code_count = code_count + 1
else:
print("Your code should include if n % (maybe_factor**2) == 0:")
# max_factor = maybe_factor
if re.search("max\_factor\s*\=\s*maybe\_factor\*\*2", code):
code_count = code_count + 1
else:
print("Your code should include max_factor = maybe_factor**2")
if code_count==2:
print("Code test passed")
print("Go on to the next step")
def step19():
print("\n Test passed. You can go on to the next step.")
def step20():
print("\n Test passed. This is this your factored square root:\n")
def step21(code):
import re
print(" ")
code_count = 0
code = In[-1].split('# Only change code above this line')[0];
if re.search("print\(round\(a\,\s*\-6\)", code):
code_count = code_count + 1
else:
print("Your code should inlcude 'print(round(a,-6)'")
if re.search("print\(round\(b\,\s*3\)", code):
code_count = code_count + 1
else:
print("Your code should inlcude 'print(round(b,3)'")
if code_count == 2:
print("Code test passed")
print("Go on to the next step")
def step22():
print(" ")
# one solution
numerator2 = int(n*10**exponent)
denominator2 = 10**exponent
percent2 = n*100
code_count = 0
if numerator2==numerator:
code_count = code_count + 1
else:
print("You should use numerator = int(n*10**exponent) in your code")
if denominator2==denominator:
code_count = code_count + 1
else:
print("You should use denominator = 10**exponent in your code")
if percent2==percent:
code_count = code_count + 1
else:
print("You should use percent = n*100 in your code")
if code_count==3:
print("Code test passed")
print("Go on to the next step")
def step23(code):
import re
print(" ")
code_count = 0
if re.search("def say\_something\(\)\:", code):
print("Now change the name of the function")
elif re.search("def fun\(\)\:", code):
code_count = code_count+1
else:
print("You should include def fun(): in your code")
if re.search("\nsay\_something\(\)", code):
print("Also remember to call the function")
elif re.search("\nfun\(\)\s*", code):
code_count = code_count+1
else:
print("Remember to call the function fun() in your code")
if code_count==2:
print("Code test passed")
print("Go on to the next step")
def step24(code):
import re
print(" ")
code_count = 0
if re.search("nom\s*\=\s*input", code):
print("Now change the variable name from 'nom' to 'nombre'")
elif re.search("nombre\s*\=\s*input", code):
code_count = code_count + 1
else:
print("Your code should include nombre = input(...")
if re.search("greeting\(nom\)", code):
print("Now change the argument when you call the function")
elif re.search("greeting\(nombre\)", code):
code_count = code_count + 1
else:
print("Your code should include greeting(nombre)")
if code_count==2:
print("Code test passed")
print("You can go on to the next step")
def step25(code):
import re
print(" ")
code_count = 0
if re.search("add\(first\,\s*second\)", code):
print("Now include the third variable when you call the function")
elif re.search("add\(first\,\s*second\,\s*third\)", code):
code_count = code_count + 1
else:
print("Your code should include add(first,second,third)")
if re.search("def add\(a\,\s*b\)\:", code):
print("Now change the argument when you define the function")
elif re.search("def add\(a\,\s*b\,\s*c\)\:", code):
code_count = code_count + 1
else:
print("Your code should include def add(a,b,c):")
if re.search("sum\s*\=\s*a\s*\+\s*b\s*\+\s*c", code):
code_count = code_count + 1
elif re.search("sum\s*\=\s*a\s*\+\s*b", code):
print("Now change the sum line in the function")
else:
print("Your code should include sum = a + b + c")
if code_count==3:
print("Code test passed")
print("You can go on to the next step")
def step26(code):
import re
print(" ")
code_count = 0
if re.search("return number\*2", code):
print("Now change the return statement in the function")
elif re.search("return number\*3", code):
print("Code test passed")
print("You can go on to the next step")
else:
print("Your code should include return number*3")
def step27(code):
print("If you didn't get a syntax error, you are ready for the project")
# probably add 3 more steps