You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _sources/functions/funcWithSetsAndDict.rst
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ You can also check if an item is in a set.
51
51
print(1 in s1)
52
52
print(9 in s1)
53
53
54
-
.. fillintheblank:: funct_tuple_test_char
54
+
.. fillintheblank:: funct_set_tuple_test_char
55
55
:practice: T
56
56
57
57
What characters are used to inintialize the values in a set in the code above?
@@ -253,7 +253,7 @@ You can use the following methods with sets.
253
253
print(s1.symmetric_difference(s2))
254
254
print(s1 ^ s2)
255
255
256
-
.. fillintheblank:: funct_exor_fitb
256
+
.. fillintheblank:: funct_set_exor_fitb
257
257
:practice: T
258
258
259
259
What character is used to find the symmetric difference (exlusive or) between two sets in the code above?
@@ -355,15 +355,15 @@ Dictionaries
355
355
356
356
A dictionary stores a value for a key. The keys must be immutable and unique.
357
357
358
-
.. fillintheblank:: funct_dict_num_t
358
+
.. fillintheblank:: funct_set_dict_num_t
359
359
360
360
What is the first thing the code below prints?
361
361
362
362
- :2: It prints the number of t's in the string.
363
363
:3: A 'T' is different from a 't'.
364
364
:.*: Try again!
365
365
366
-
.. activecode:: func_dict_example
366
+
.. activecode:: func_set_dict_example
367
367
:caption: Example with a dictionary
368
368
369
369
Run this code to see what it prints.
@@ -385,12 +385,12 @@ A dictionary stores a value for a key. The keys must be immutable and unique.
385
385
print(d1)
386
386
print(type(d1))
387
387
388
-
.. shortanswer:: func_dict_key_error_sa
388
+
.. shortanswer:: func_set_dict_key_error_sa
389
389
390
390
Look at the Python code below. What do you think will happen when you run the following code?
391
391
392
392
393
-
.. activecode:: func_dict_with_key_error
393
+
.. activecode:: func_set_dict_with_key_error
394
394
:caption: Example with a dictionary
395
395
396
396
Run this code to see what it prints.
@@ -402,7 +402,7 @@ A dictionary stores a value for a key. The keys must be immutable and unique.
402
402
403
403
There is another way to update the value for a key that works even if the key isn't in the dictionary already.
404
404
405
-
.. activecode:: func_dict_example_v2
405
+
.. activecode:: func_set_dict_example_v2
406
406
:caption: Example with a dictionary
407
407
408
408
Run this code to see what it prints.
@@ -467,5 +467,5 @@ There is another way to update the value for a key that works even if the key is
467
467
468
468
If you worked in a group, you can copy the answers from this page to the other group members. Select the group members below and click the button to share the answers.
Copy file name to clipboardExpand all lines: _sources/functions/func_Str_Cond.rst
+25-10Lines changed: 25 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,8 @@ in groups on activities and each member has an assigned role. For more informat
8
8
9
9
If you work in a group, have only one member of the group fill in the answers on this page. You will be able to share your answers with the group at the bottom of the page.
10
10
11
-
**Learning Objectives**
11
+
Learning Objectives
12
+
====================
12
13
13
14
Students will know and be able to do the following.
14
15
@@ -131,6 +132,8 @@ a string covers more than one line.
131
132
String Indices
132
133
==================
133
134
135
+
You can get a character from a string at an index (position) using ``string[index]``.
136
+
134
137
.. fillintheblank:: fsc_fitb_pogil_initials_v2
135
138
136
139
What is the last thing that will be printed when the code below runs?
@@ -141,7 +144,7 @@ String Indices
141
144
.. activecode:: fsc_ac_pogil_initials_v2
142
145
:caption: get_initials
143
146
144
-
Run the code below to see what it prints. Then fix it to pass the given test. It should return a string with the
147
+
Run the code below to see what it prints. Then fix it to pass the test shown below the code. It should return a string with the
145
148
first character of the first name and first character of the last name.
146
149
~~~~
147
150
# function definition
@@ -160,6 +163,7 @@ String Indices
160
163
# function call
161
164
main()
162
165
166
+
====
163
167
from unittest.gui import TestCaseGui
164
168
class myTests(TestCaseGui):
165
169
@@ -172,13 +176,15 @@ String Indices
172
176
173
177
.. note::
174
178
175
-
Use [index] to get a character from a string. The first character in a string is at index 0 and the last is at the length of the string minus 1 (also know as index -1 in Python).
179
+
Use ``string[index]`` to get a character from a string. The first character in a string is at index 0 and the last is at the length of the string minus 1 (also know as index -1 in Python).
176
180
177
181
Fix the function ``get_initials`` above to return a string with the first letter of the first name followed by the first letter of the last name.
178
182
179
183
String Slices
180
184
==================
181
185
186
+
You can get a copy of part or all of a string using ``str_name[start:end]``.
187
+
182
188
.. fillintheblank:: fsc_fitb_pogil_short_name
183
189
184
190
What is the last thing that will be printed when the code below runs?
@@ -217,6 +223,14 @@ String Slices
217
223
- :dna\[0\:3\]|\[:3\]: This will return a new string with the characters from index 0 to 2.
218
224
:.*: Look at the note above and try again.
219
225
226
+
.. fillintheblank:: fsc_fitb_len_string
227
+
:practice: T
228
+
229
+
What built-in function tells you the number of characters in a string?
230
+
231
+
- :len: The len function takes a string and returns the number of characters in it.
232
+
:.*: Look at the example code above.
233
+
220
234
221
235
Basic Conditionals and Tests
222
236
============================
@@ -237,13 +251,13 @@ Basic Conditionals and Tests
237
251
# function definition
238
252
def get_temp_desc(temp):
239
253
if temp < 32:
240
-
return "Baby, its cold outside!"
254
+
return "Baby, its cold outside! The temp is " + str(temp)
241
255
elif temp < 70:
242
-
return "Wear a coat"
256
+
return "Wear a coat The temp is " + str(temp)
243
257
elif temp < 80:
244
-
return "Feels great!"
258
+
return "Feels great! The temp is " + str(temp)
245
259
else:
246
-
return "Too hot to handle!"
260
+
return "Too hot to handle! The temp is " + str(temp)
247
261
248
262
# function definition
249
263
def main():
@@ -253,6 +267,10 @@ Basic Conditionals and Tests
253
267
# function call
254
268
main()
255
269
270
+
.. note::
271
+
272
+
You must first convert a number to a string using ``str(nun)`` if you want to add it to a string using ``+``.
273
+
256
274
.. fillintheblank:: fsc_fitb_pogil_elif
257
275
258
276
What keyword is used in a conditional statement when you want three of more possible outcomes?
@@ -286,9 +304,6 @@ Basic Conditionals and Tests
286
304
# function call
287
305
main()
288
306
289
-
.. note::
290
-
291
-
You must first convert a number to a string using ``str(nun)`` if you want to add it to a string using ``+``.
0 commit comments