Mini-exercise: variables, expressions, types, screen I/O

Note: As you may have noticed, when you run the Python interpreter interactively, any expression you enter is evaluated and the result is printed directly to the screen. This is nice. But to do the mini-exercises throughout this topic, it is best if you can create a script that you edit and run as needed. The previous section on Running a Saved Program is a suitable guide on how to do this.

Now, try to “think like the interpreter” when dealing with the following mixed types...

  1. Do (accidental?) math with True (=1) and False (=0)!
  2. Use explicit type conversion to stay safe!

The point is not just to help you write good Python programs—it is also to show you what can go wrong!

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement