Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 941 Bytes

ex29.rst

File metadata and controls

34 lines (23 loc) · 941 Bytes

Exercise 29: What If

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:


What You Should See

.. literalinclude:: ex/ex29.txt
    :language: console



Extra Credit

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:

  1. What do you think the if does to the code under it?
  2. Why does the code under the if need to be indented 4 spaces?
  3. What happens if it isn't indented?
  4. Can you put other boolean expressions from Ex. 27 in the if-statement? Try it.
  5. What happens if you change the initial variables for people, cats, and dogs?