Skip to content

Commit e9a523a

Browse files
Update sb_template.py
1 parent 2846879 commit e9a523a

File tree

1 file changed

+7
-33
lines changed

1 file changed

+7
-33
lines changed

sb_template.py

+7-33
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,16 @@ def bot(ted, question):
4949
"""
5050
# Init LED happy image
5151
display.show(Image.HAPPY)
52-
5352
# This is an advanced topic as well however this little function
5453
# cleans out the unnecessary global objects or variables on what
5554
# we call the heap area in memory
5655
gc.collect()
57-
5856
# Init response object
59-
response = ''
60-
57+
response = ''
6158
# We want to make sure that our dictionary database can
6259
# find all values even if you use a capital letter
6360
# so we convert everything to lowercase
6461
question = question.lower()
65-
6662
# If you type something other than an empty string that means
6763
# question has a value so the rest of the code will continue
6864
# on
@@ -74,7 +70,6 @@ def bot(ted, question):
7470
# put the value in the _response object
7571
response = [val for key, val in ted.items() if key in question]
7672
gc.collect()
77-
7873
# If our bot got a response from us then make sure
7974
# we trigger the speaking or suprised image so our bot
8075
# can open its mouth to talk and then have our bot
@@ -90,8 +85,7 @@ def bot(ted, question):
9085
display.show(Image.SURPRISED)
9186
print('BOT: That is not something I am familiar with.')
9287
say('That is not something I am familiar with.', speed=SPEED)
93-
display.show(Image.HAPPY)
94-
88+
display.show(Image.HAPPY)
9589
gc.collect()
9690

9791

@@ -104,22 +98,18 @@ def quiz_f(teq):
10498
"""
10599
# Init LED happy image
106100
display.show(Image.HAPPY)
107-
108101
# This is an advanced topic as well however this little function
109102
# cleans out the unnecessary global objects or variables on what
110103
# we call the heap area in memory
111104
gc.collect()
112-
113105
# Init score object
114106
score = 0
115-
116107
# Here we iterate through our quiz database
117108
for key in teq:
118109
print(key)
119110
say(str(key), speed=SPEED)
120111
response = input('ANSWER: ')
121-
response = response.lower()
122-
112+
response = response.lower()
123113
correct_answer = teq[key].lower()
124114
if response == correct_answer:
125115
display.show(Image.SURPRISED)
@@ -133,10 +123,8 @@ def quiz_f(teq):
133123
say('The correct answer is', speed=SPEED)
134124
say(str(teq[key]), speed=SPEED)
135125
display.show(Image.HAPPY)
136-
137126
time.sleep(1)
138127
gc.collect()
139-
140128
# Here we reply to the student their score
141129
display.show(Image.SURPRISED)
142130
print('You got {0} out of {1} correct!'.format(score, len(teq)))
@@ -145,7 +133,6 @@ def quiz_f(teq):
145133
say('out of', speed=SPEED)
146134
say(str(len(teq)), speed=SPEED)
147135
say('correct!', speed=SPEED)
148-
149136
# If student got a perfect score respond appropriately
150137
# or provide an encouring message to retry the quiz
151138
if score == len(teq):
@@ -160,8 +147,7 @@ def quiz_f(teq):
160147
print('You are doing a great job!')
161148
say('You are doing a great job!', speed=SPEED)
162149
print('I would LOVE for you to try again!')
163-
say('I would LOVE for you to try again!', speed=SPEED)
164-
150+
say('I would LOVE for you to try again!', speed=SPEED)
165151
# Display happy response at the end of the quiz
166152
display.show(Image.HAPPY)
167153
gc.collect()
@@ -176,15 +162,12 @@ def quiz_m(teq):
176162
"""
177163
# Init LED happy image
178164
display.show(Image.HAPPY)
179-
180165
# This is an advanced topic as well however this little function
181166
# cleans out the unnecessary global objects or variables on what
182167
# we call the heap area in memory
183168
gc.collect()
184-
185169
# Init score object
186170
score = 0
187-
188171
# Here we iterate through our quiz database with multiple
189172
# choice items
190173
for key in teq:
@@ -193,21 +176,18 @@ def quiz_m(teq):
193176
say(str(key), speed=SPEED)
194177
display.show(Image.HAPPY)
195178
time.sleep(1)
196-
197179
display.show(Image.SURPRISED)
198180
print('Press A for {0}.'.format(teq[key][0]))
199181
say('Press Ayyy for', speed=SPEED)
200182
say(str(teq[key][0]), speed=SPEED)
201183
display.show(Image.HAPPY)
202184
time.sleep(1)
203-
204185
display.show(Image.SURPRISED)
205186
print('Touch the logo for {0}.'.format(teq[key][1]))
206187
say('Toch the logo for', speed=SPEED)
207188
say(str(teq[key][1]), speed=SPEED)
208189
display.show(Image.HAPPY)
209190
time.sleep(1)
210-
211191
display.show(Image.SURPRISED)
212192
print('Press B for {0}.'.format(teq[key][2]))
213193
say('Press B for', speed=SPEED)
@@ -224,16 +204,14 @@ def quiz_m(teq):
224204
response = 2
225205
break
226206
else:
227-
pass
228-
207+
pass
229208
correct_answer = teq[key][3]
230209
display.show(Image.SURPRISED)
231210
print('You selected {0}.'.format(teq[key][response]))
232211
say('You selected', speed=SPEED)
233212
say(str(teq[key][response]), speed=SPEED)
234213
display.show(Image.HAPPY)
235214
time.sleep(1)
236-
237215
if response == correct_answer:
238216
display.show(Image.SURPRISED)
239217
print('CORRECT!')
@@ -245,11 +223,9 @@ def quiz_m(teq):
245223
print('The correct answer is {0}.'.format(teq[key][correct_answer]))
246224
say('The correct answer is', speed=SPEED)
247225
say(str(teq[key][correct_answer]), speed=SPEED)
248-
display.show(Image.HAPPY)
249-
226+
display.show(Image.HAPPY)
250227
time.sleep(1)
251-
gc.collect()
252-
228+
gc.collect()
253229
# Here we reply to the student their score
254230
display.show(Image.SURPRISED)
255231
print('You got {0} out of {1} correct!'.format(score, len(teq)))
@@ -260,7 +236,6 @@ def quiz_m(teq):
260236
say('correct!', speed=SPEED)
261237
display.show(Image.HAPPY)
262238
time.sleep(1)
263-
264239
# If student got a perfect score respond appropriately
265240
# or provide an encouring message to retry the quiz
266241
display.show(Image.SURPRISED)
@@ -277,7 +252,6 @@ def quiz_m(teq):
277252
say('You are doing a great job!', speed=SPEED)
278253
print('I would LOVE for you to try again!')
279254
say('I would LOVE for you to try again!', speed=SPEED)
280-
281255
# Display happy response at the end of the quiz
282256
display.show(Image.HAPPY)
283257
time.sleep(1)

0 commit comments

Comments
 (0)