Skip to content

Commit 37cba64

Browse files
committed
Syncing the rst and PreTeXt
1 parent 126be33 commit 37cba64

2 files changed

Lines changed: 55 additions & 14 deletions

File tree

_sources/functions/func_Str_Cond.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ in groups on activities and each member has an assigned role. For more informat
88

99
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.
1010

11-
**Learning Objectives**
11+
Learning Objectives
12+
====================
1213

1314
Students will know and be able to do the following.
1415

@@ -131,6 +132,8 @@ a string covers more than one line.
131132
String Indices
132133
==================
133134

135+
You can get a character from a string at an index (position) using ``string[index]``.
136+
134137
.. fillintheblank:: fsc_fitb_pogil_initials_v2
135138

136139
What is the last thing that will be printed when the code below runs?
@@ -141,7 +144,7 @@ String Indices
141144
.. activecode:: fsc_ac_pogil_initials_v2
142145
:caption: get_initials
143146

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
145148
first character of the first name and first character of the last name.
146149
~~~~
147150
# function definition
@@ -160,6 +163,7 @@ String Indices
160163
# function call
161164
main()
162165

166+
====
163167
from unittest.gui import TestCaseGui
164168
class myTests(TestCaseGui):
165169

@@ -172,13 +176,15 @@ String Indices
172176

173177
.. note::
174178

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).
176180

177181
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.
178182

179183
String Slices
180184
==================
181185

186+
You can get a copy of part or all of a string using ``str_name[start:end]``.
187+
182188
.. fillintheblank:: fsc_fitb_pogil_short_name
183189

184190
What is the last thing that will be printed when the code below runs?
@@ -217,6 +223,14 @@ String Slices
217223
- :dna\[0\:3\]|\[:3\]: This will return a new string with the characters from index 0 to 2.
218224
:.*: Look at the note above and try again.
219225

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+
220234

221235
Basic Conditionals and Tests
222236
============================
@@ -237,13 +251,13 @@ Basic Conditionals and Tests
237251
# function definition
238252
def get_temp_desc(temp):
239253
if temp < 32:
240-
return "Baby, its cold outside!"
254+
return "Baby, its cold outside! The temp is " + str(temp)
241255
elif temp < 70:
242-
return "Wear a coat"
256+
return "Wear a coat The temp is " + str(temp)
243257
elif temp < 80:
244-
return "Feels great!"
258+
return "Feels great! The temp is " + str(temp)
245259
else:
246-
return "Too hot to handle!"
260+
return "Too hot to handle! The temp is " + str(temp)
247261

248262
# function definition
249263
def main():
@@ -253,6 +267,10 @@ Basic Conditionals and Tests
253267
# function call
254268
main()
255269

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+
256274
.. fillintheblank:: fsc_fitb_pogil_elif
257275

258276
What keyword is used in a conditional statement when you want three of more possible outcomes?
@@ -286,9 +304,6 @@ Basic Conditionals and Tests
286304
# function call
287305
main()
288306

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 ``+``.
292307

293308
.. parsonsprob:: fsc_pogil_check-guess-Parsons-v2
294309
:numbered: left

pretext/functions/funcWithStrsAndConds.ptx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ myTests().main()
277277
</exercise>
278278

279279
<note>
280-
<p>The first character is at index 0 and an index of -1 means the last charater.</p>
280+
<p>Use <c>string[index]</c> 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)</p>
281281
</note>
282282
</subsection>
283283
<subsection xml:id="fsc_string-slices">
284-
<title>String Slices</title>
284+
<title>String Slices</title>
285+
<p>You can get a copy of part or all of a string using <c>str_name[start:end]</c>.</p>
285286
<exercise label="fsc_fitb_pogil_short_name">
286-
<p>You can get a copy of part or all of a string using <c>str_name[start:end]</c>.</p>
287287
<statement>
288288
<p>What is the last thing that will be printed when the code below runs? <var/> </p>
289289
</statement>
@@ -324,7 +324,7 @@ main()
324324
</program>
325325
</exercise>
326326
<note>
327-
<p>Use the slice [start:end] operator to get a slice (substring) from a string. It will return a new string starting at the start and including all the characters up to just before the end (end - 1).</p>
327+
<p>Use the slice [start:end] operator to get a slice (substring) from a string. It will return a new string starting at the start and including all the characters up to just before the end (end - 1). If ``start`` is missing the default is 0 and if ``end`` is missing the default value is the length of the string.</p>
328328
</note>
329329
<exercise label="fsc_fitb_three_char_slice">
330330
<statement>
@@ -656,6 +656,32 @@ myTests().main()
656656
</input>
657657
</program>
658658
</exercise>
659+
660+
.. activecode:: fsc_ac_or_complex_cond
661+
:caption: complex conditional
662+
663+
Modify this code to use a complex conditional instead. It should still pass all tests. It should only take four lines of code or less.
664+
~~~~
665+
# function definition
666+
def either6(a,b):
667+
if a == 6:
668+
return True
669+
if b == 6:
670+
return True
671+
return False
672+
673+
====
674+
from unittest.gui import TestCaseGui
675+
676+
class myTests(TestCaseGui):
677+
678+
def testOne(self):
679+
self.assertEqual(either6(5,2),False,"either6(5,2)")
680+
self.assertEqual(either6(6,3),True, "either6(6,3)")
681+
self.assertEqual(either6(3,6),True, "either6(3,6)")
682+
self.assertEqual(either6(3,-6),False, "either6(3,6)")
683+
684+
myTests().main()
659685
</subsection>
660686
</section>
661687
</worksheet>

0 commit comments

Comments
 (0)