Lecture 5: Booleans and Conditionals
Slides
Four per page (with some fill-in-the-blanks): A PDF file of the lecture slides handout. We'll provide a printed copy in lectu re for you to make notes on.
Readings
Think Python, Ch. 5: Conditionals [Sections 5.1 - 5.7].
Code
Click on this lecture_05.zip link to download the .zip
file to your computer.
Folder contains the Notebook for lecture activities.
Solutions
Complete pdf version of slides (with fill-in-the-blanks-filled-in).
Snow Day Announcements
Classes were cancelled for this lecture day due to a snow storm. Here were the announcements related to that closure.
First, the 10-minute quiz that was scheduled for the beginning of today’s class will instead be held at the beginning of class on Mon. Feb 13.
Second, PS2 will still be due at 11:59pm on Mon. Feb 13. We will monitor the weather conditions and notify you via email whether the scheduled Drop-In hours for Thu, 02/09, 6-10pm will take place or be canceled. As always, you can use the Google Group to ask questions about the material and the problem sets.
Third, in order to keep on track with the CS111 schedule, you should (alone or in groups) cover the material in today’s slides, notebook, and reading on Booleans and Conditionals. You can do this in stages:
-
Stage 1: Booleans, Relational Operators, Logical Operators, and Predicates: Cover slides 5-1 through 5-12 and the corresponding material in the notebook, culminating in the exercises on slide 5-12, which you should do in the notebook. We have a Lec 05 Part 1 screencast from Spring ‘15 that covers much of the same material, but uses Canopy directly rather than a notebook. The solutions to the exercises are discussed in the first 3 minutes of the Lec 05 Part 2 screencast from Spring ‘15, including the incorrect solution for isVowelBuggy on slide 5-13.
-
Stage 2: Conditionals Cover slides 5-14 through 5-22, culminating on the
letterGrade
,addArticle
, anddaysInMonth
exercises. Similar material is covered in the Lec 05 Part 2 screencast from Spring ‘15. The solutions toaddArticle
are explained in the first 2.5 minutes of the Lec 05 Part 3 screencast from Spring ‘15. This is followed by a solution to another function using conditionals,sumUnique
, that is not covered in the Spring ‘17 slides. -
Stage 3: Digging Deeper Material Slides 5-23 through 5-31 cover material related to booleans and conditionals that we do not require, but is worth knowing. Some extra details:
-
Short-circuit evaluation (slide 5-23) is explained from 6:05 to 7:37 in the Lec 05 Part 1 screencast from Spring ‘15
- Long return expressions and the backslash line continuation character \ (slide 5-26 ) is explained from 11:55 to 13:02 in the Lec 05 Part 1 screencast from Spring ‘15.
-
Truthiness and falsiness and why isVowelBuggy
doesn’t work (slides 5-27 and 5-28) is explained from 5:55 to 11:11 in the Lec 05 Part 3 screencast from Spring ‘15.