Here is the next script of Python you will enter, which introduces you to
the if-statement
. Type this in, make it run exactly right, and then
we'll try see if your practice has paid off.
.. literalinclude:: ex/ex29.py :linenos:
.. literalinclude:: ex/ex29.txt :language: console
In this extra credit, try to guess what you think the if-statement
is and
what it does. Try to answer these questions in your own words before moving
onto the next exercise:
- What do you think the
if
does to the code under it? - Why does the code under the
if
need to be indented 4 spaces? - What happens if it isn't indented?
- Can you put other boolean expressions from Ex. 27 in the
if-statement
? Try it. - What happens if you change the initial variables for
people
,cats
, anddogs
?