Skip to content

Commit b9e6dae

Browse files
committed
Update funcWithStrsAndConds.ptx
1 parent e99dc30 commit b9e6dae

1 file changed

Lines changed: 45 additions & 86 deletions

File tree

pretext/functions/funcWithStrsAndConds.ptx

Lines changed: 45 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ a string covers more than one line. </p>
221221
</subsection>
222222
<subsection xml:id="fsc_str_cond_string_index">
223223
<title>String Indices</title>
224-
<p>You can get a character from a string at an index (position).</p>
224+
<p>You can get a character from a string at an index (position) using <c>string[index]</c>.</p>
225225
<exercise label="fsc_fitb_pogil_initials">
226226
<statement>
227227
<p>What is the last thing that will be printed when the code below runs? <var/> </p>
@@ -361,6 +361,38 @@ main()
361361
</var>
362362
</setup>
363363
</exercise>
364+
365+
<exercise label="fsc_pogil_get_last_half_v2">
366+
<statement>
367+
<p>Finish the function <c>last_half(str)</c> which
368+
returns the last half of the characters from the passed string <c>str</c>.
369+
If <c>str</c> has less than 2 characters then return the empty string <c>""</c>.
370+
For example, <c>last_half("a")</c> returns <c>""</c>, <c>last_half("coal")</c> returns <c>"al"</c>, and <c>last_half("bye")</c> returns <c>ye</c>.</p>
371+
</statement>
372+
<program xml:id="funct_pogil_get_last_half_editor" interactive="activecode" language="python">
373+
<input>
374+
def last_half(str):
375+
376+
====
377+
from unittest.gui import TestCaseGui
378+
379+
class myTests(TestCaseGui):
380+
381+
def testOne(self):
382+
self.assertEqual(last_half('a'), '', "last_half('a')")
383+
self.assertEqual(last_half('coal'), 'al', "last_half('coal')")
384+
self.assertEqual(last_half('bye'), 'ye', "last_half('bye')")
385+
self.assertEqual(last_half('abcd'), 'cd', "last_half('abcd')")
386+
self.assertEqual(last_half('12345'), '345', "last_half('12345')")
387+
self.assertEqual(last_half('123456'), '456', "last_half('123456')")
388+
self.assertEqual(last_half('ab'), 'b', "last_half('ab')")
389+
self.assertEqual(last_half(''), '', "last_half('')")
390+
391+
392+
myTests().main()
393+
</input>
394+
</program>
395+
</exercise>
364396

365397
</subsection>
366398

@@ -385,22 +417,22 @@ main()
385417
</var>
386418
</setup>
387419
</exercise>
388-
<exercise label="fsc_ac_pogil_return_temp_desc">
420+
<exercise label="fsc_ac_pogil_return_temp_desc2">
389421
<statement>
390422
<p>Run this code to see what it prints.</p>
391423
</statement>
392-
<program xml:id="fsc_ac_pogil_return_temp_desc_editor" interactive="activecode" language="python">
424+
<program xml:id="fsc_ac_pogil_return_temp_desc2_editor" interactive="activecode" language="python">
393425
<input>
394426
# function definition
395427
def get_temp_desc(temp):
396428
if temp &lt; 32:
397-
return "Baby, its cold outside!"
429+
return "Baby, its cold outside! The temp is " + str(temp)
398430
elif temp &lt; 70:
399-
return "Wear a coat"
431+
return "Wear a coat. The temp is " + str(temp)
400432
elif temp &lt; 80:
401-
return "Feels great!"
433+
return "Feels great! The temp is " + str(temp)
402434
else:
403-
return "Too hot to handle!"
435+
return "Too hot to handle! The temp is " + str(temp)
404436

405437
# function definition
406438
def main():
@@ -412,54 +444,11 @@ main()
412444
</input>
413445
</program>
414446
</exercise>
415-
<exercise label="fsc_fitb_pogil_exec_false">
416-
<statement>
417-
<p>What keyword specifies the block of statements to execute if a Boolean condition is false? <var/> </p>
418-
</statement>
419-
<setup>
420-
<var>
421-
<condition string="else">
422-
<feedback>
423-
<p>The keyword else is used to execute a blocks of statements if a Boolean condition is false</p>
424-
</feedback>
425-
</condition>
426-
<condition string="Else">
427-
<feedback>
428-
<p>Most keywords in Python start with a lowercase letter</p>
429-
</feedback>
430-
</condition>
431-
<condition string=".*">
432-
<feedback>
433-
<p>Try again!</p>
434-
</feedback>
435-
</condition>
436-
</var>
437-
</setup>
438-
</exercise>
439-
<exercise label="fsc_fitb_pogil_conditional_start">
440-
<statement>
441-
<p>What keyword starts a conditional statement and is the only required keyword in it? <var/> </p>
442-
</statement>
443-
<setup>
444-
<var>
445-
<condition string="if">
446-
<feedback>
447-
<p>The keyword if is used to start a conditional statement and is the only required keyword.</p>
448-
</feedback>
449-
</condition>
450-
<condition string="If">
451-
<feedback>
452-
<p>Most keywords in Python start with a lowercase letter</p>
453-
</feedback>
454-
</condition>
455-
<condition string=".*">
456-
<feedback>
457-
<p>Try again!</p>
458-
</feedback>
459-
</condition>
460-
</var>
461-
</setup>
462-
</exercise>
447+
448+
<note>
449+
<p>You must first convert a number to a string using <c>str(number)</c> before you add it to a string using <c>+</c>.</p>
450+
</note>
451+
463452
<exercise label="fsc_fitb_pogil_multi_conditonal">
464453
<statement>
465454
<p>What keyword is used in a conditional statement when you want three of more possible outcomes? <var/> </p>
@@ -558,37 +547,7 @@ main()
558547
</block>
559548
</blocks>
560549
</exercise>
561-
<exercise label="fsc_pogil_get_last_half_v2">
562-
<statement>
563-
<p>Finish the function <c>last_half(str)</c> which
564-
returns the last half of the characters from the passed string <c>str</c>.
565-
If <c>str</c> has less than 2 characters then return the empty string <c>""</c>.
566-
For example, <c>last_half("a")</c> returns <c>""</c>, <c>last_half("coal")</c> returns <c>"al"</c>, and <c>last_half("bye")</c> returns <c>ye</c>.</p>
567-
</statement>
568-
<program xml:id="funct_pogil_get_last_half_editor" interactive="activecode" language="python">
569-
<input>
570-
def last_half(str):
571-
572-
====
573-
from unittest.gui import TestCaseGui
574-
575-
class myTests(TestCaseGui):
576-
577-
def testOne(self):
578-
self.assertEqual(last_half('a'), '', "last_half('a')")
579-
self.assertEqual(last_half('coal'), 'al', "last_half('coal')")
580-
self.assertEqual(last_half('bye'), 'ye', "last_half('bye')")
581-
self.assertEqual(last_half('abcd'), 'cd', "last_half('abcd')")
582-
self.assertEqual(last_half('12345'), '345', "last_half('12345')")
583-
self.assertEqual(last_half('123456'), '456', "last_half('123456')")
584-
self.assertEqual(last_half('ab'), 'b', "last_half('ab')")
585-
self.assertEqual(last_half(''), '', "last_half('')")
586-
587-
588-
myTests().main()
589-
</input>
590-
</program>
591-
</exercise>
550+
592551
<exercise label="fsc_fitb_cond_predict_grade">
593552
<statement>
594553
<p>What is the first thing that will be printed when the code below runs? <var/> </p>

0 commit comments

Comments
 (0)