Skip to content

Commit e99dc30

Browse files
committed
Update funcWithStrsAndConds.ptx
1 parent 6484f3d commit e99dc30

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

pretext/functions/funcWithStrsAndConds.ptx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,5 +660,41 @@ main()
660660
</setup>
661661
</exercise>
662662
</subsection>
663+
664+
<subsection xml:id="fsc_logical-operators-and-complex-conditionals">
665+
<title>Logical Operators and Complex Conditionals</title>
666+
<p>The logical operators in Python are <c>and</c>, <c>or</c>, and <c>not</c>. These can be used to create complex conditionals.</p>
667+
<exercise label="func_ac_and_complex_cond">
668+
<statement>
669+
<p>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.</p>
670+
</statement>
671+
<program xml:id="func_ac_and_complex_cond_editor" interactive="activecode" language="python">
672+
<input>
673+
# function definition
674+
def test(a):
675+
if a &gt; 0:
676+
if a &lt;= 10:
677+
return True
678+
return False
679+
680+
====
681+
from unittest.gui import TestCaseGui
682+
683+
class myTests(TestCaseGui):
684+
685+
def testOne(self):
686+
self.assertEqual(test(5),True,"test(5)")
687+
self.assertEqual(test(0),False,"test(0)")
688+
self.assertEqual(test(1),True,"test(1)")
689+
self.assertEqual(test(-5),False,"test(-5)")
690+
self.assertEqual(test(11),False,"test(11)")
691+
self.assertEqual(test(10),True,"test(10)")
692+
self.assertEqual(test(9),True,"test(9)")
693+
694+
myTests().main()
695+
</input>
696+
</program>
697+
</exercise>
698+
</subsection>
663699
</section>
664700
</worksheet>

0 commit comments

Comments
 (0)