@@ -210,20 +210,16 @@ def bot(ted, question):
210
210
"""
211
211
# Init LED happy image
212
212
display .show (Image .HAPPY )
213
-
214
213
# This is an advanced topic as well however this little function
215
214
# cleans out the unnecessary global objects or variables on what
216
215
# we call the heap area in memory
217
216
gc .collect ()
218
-
219
217
# Init response object
220
218
response = ''
221
-
222
219
# We want to make sure that our dictionary database can
223
220
# find all values even if you use a capital letter
224
221
# so we convert everything to lowercase
225
222
question = question .lower ()
226
-
227
223
# If you type something other than an empty string that means
228
224
# question has a value so the rest of the code will continue
229
225
# on
@@ -235,7 +231,6 @@ def bot(ted, question):
235
231
# put the value in the _response object
236
232
response = [val for key , val in ted .items () if key in question ]
237
233
gc .collect ()
238
-
239
234
# If our bot got a response from us then make sure
240
235
# we trigger the speaking or suprised image so our bot
241
236
# can open its mouth to talk and then have our bot
@@ -264,22 +259,18 @@ def quiz_f(teq):
264
259
"""
265
260
# Init LED happy image
266
261
display .show (Image .HAPPY )
267
-
268
262
# This is an advanced topic as well however this little function
269
263
# cleans out the unnecessary global objects or variables on what
270
264
# we call the heap area in memory
271
265
gc .collect ()
272
-
273
266
# Init score object
274
267
score = 0
275
-
276
268
# Here we iterate through our quiz database
277
269
for key in teq :
278
270
print (key )
279
271
say (str (key ), speed = SPEED )
280
272
response = input ('ANSWER: ' )
281
273
response = response .lower ()
282
-
283
274
correct_answer = teq [key ].lower ()
284
275
if response == correct_answer :
285
276
display .show (Image .SURPRISED )
@@ -292,20 +283,17 @@ def quiz_f(teq):
292
283
print ('The correct answer is {0}.' .format (teq [key ]))
293
284
say ('The correct answer is' , speed = SPEED )
294
285
say (str (teq [key ]), speed = SPEED )
295
- display .show (Image .HAPPY )
296
-
286
+ display .show (Image .HAPPY )
297
287
time .sleep (1 )
298
- gc .collect ()
299
-
288
+ gc .collect ()
300
289
# Here we reply to the student their score
301
290
display .show (Image .SURPRISED )
302
291
print ('You got {0} out of {1} correct!' .format (score , len (teq )))
303
292
say ('You got' , speed = SPEED )
304
293
say (str (score ), speed = SPEED )
305
294
say ('out of' , speed = SPEED )
306
295
say (str (len (teq )), speed = SPEED )
307
- say ('correct!' , speed = SPEED )
308
-
296
+ say ('correct!' , speed = SPEED )
309
297
# If student got a perfect score respond appropriately
310
298
# or provide an encouring message to retry the quiz
311
299
if score == len (teq ):
@@ -320,8 +308,7 @@ def quiz_f(teq):
320
308
print ('You are doing a great job!' )
321
309
say ('You are doing a great job!' , speed = SPEED )
322
310
print ('I would LOVE for you to try again!' )
323
- say ('I would LOVE for you to try again!' , speed = SPEED )
324
-
311
+ say ('I would LOVE for you to try again!' , speed = SPEED )
325
312
# Display happy response at the end of the quiz
326
313
display .show (Image .HAPPY )
327
314
gc .collect ()
@@ -336,15 +323,12 @@ def quiz_m(teq):
336
323
"""
337
324
# Init LED happy image
338
325
display .show (Image .HAPPY )
339
-
340
326
# This is an advanced topic as well however this little function
341
327
# cleans out the unnecessary global objects or variables on what
342
328
# we call the heap area in memory
343
329
gc .collect ()
344
-
345
330
# Init score object
346
331
score = 0
347
-
348
332
# Here we iterate through our quiz database with multiple
349
333
# choice items
350
334
for key in teq :
@@ -353,21 +337,18 @@ def quiz_m(teq):
353
337
say (str (key ), speed = SPEED )
354
338
display .show (Image .HAPPY )
355
339
time .sleep (1 )
356
-
357
340
display .show (Image .SURPRISED )
358
341
print ('Press A for {0}.' .format (teq [key ][0 ]))
359
342
say ('Press Ayyy for' , speed = SPEED )
360
343
say (str (teq [key ][0 ]), speed = SPEED )
361
344
display .show (Image .HAPPY )
362
345
time .sleep (1 )
363
-
364
346
display .show (Image .SURPRISED )
365
347
print ('Touch the logo for {0}.' .format (teq [key ][1 ]))
366
348
say ('Toch the logo for' , speed = SPEED )
367
349
say (str (teq [key ][1 ]), speed = SPEED )
368
350
display .show (Image .HAPPY )
369
351
time .sleep (1 )
370
-
371
352
display .show (Image .SURPRISED )
372
353
print ('Press B for {0}.' .format (teq [key ][2 ]))
373
354
say ('Press B for' , speed = SPEED )
@@ -385,15 +366,13 @@ def quiz_m(teq):
385
366
break
386
367
else :
387
368
pass
388
-
389
369
correct_answer = teq [key ][3 ]
390
370
display .show (Image .SURPRISED )
391
371
print ('You selected {0}.' .format (teq [key ][response ]))
392
372
say ('You selected' , speed = SPEED )
393
373
say (str (teq [key ][response ]), speed = SPEED )
394
374
display .show (Image .HAPPY )
395
- time .sleep (1 )
396
-
375
+ time .sleep (1 )
397
376
if response == correct_answer :
398
377
display .show (Image .SURPRISED )
399
378
print ('CORRECT!' )
@@ -405,11 +384,9 @@ def quiz_m(teq):
405
384
print ('The correct answer is {0}.' .format (teq [key ][correct_answer ]))
406
385
say ('The correct answer is' , speed = SPEED )
407
386
say (str (teq [key ][correct_answer ]), speed = SPEED )
408
- display .show (Image .HAPPY )
409
-
387
+ display .show (Image .HAPPY )
410
388
time .sleep (1 )
411
- gc .collect ()
412
-
389
+ gc .collect ()
413
390
# Here we reply to the student their score
414
391
display .show (Image .SURPRISED )
415
392
print ('You got {0} out of {1} correct!' .format (score , len (teq )))
@@ -419,8 +396,7 @@ def quiz_m(teq):
419
396
say (str (len (teq )), speed = SPEED )
420
397
say ('correct!' , speed = SPEED )
421
398
display .show (Image .HAPPY )
422
- time .sleep (1 )
423
-
399
+ time .sleep (1 )
424
400
# If student got a perfect score respond appropriately
425
401
# or provide an encouring message to retry the quiz
426
402
display .show (Image .SURPRISED )
@@ -436,8 +412,7 @@ def quiz_m(teq):
436
412
print ('You are doing a great job!' )
437
413
say ('You are doing a great job!' , speed = SPEED )
438
414
print ('I would LOVE for you to try again!' )
439
- say ('I would LOVE for you to try again!' , speed = SPEED )
440
-
415
+ say ('I would LOVE for you to try again!' , speed = SPEED )
441
416
# Display happy response at the end of the quiz
442
417
display .show (Image .HAPPY )
443
418
time .sleep (1 )
0 commit comments