Comparisons

Flash and JavaScript are required for this feature.

Download the video from iTunes U or the Internet Archive.

Description: This in-class exercise demonstrates how conditionals and comparisons work in Python.

Instructor: Dr. Ana Bell

The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To make a donation or view additional materials from hundreds of MIT courses, visit MIT OpenCourseWare at ocw.mit.edu.

ANA BELL: So I'm creating a variable called pset_time and I'm assigning it to be the value 15. I'm creating a variable named sleep_time. I'm assigning it to be the value 8. I'm going to print the value of this expression here. And the expression is a conditional that says, is sleep_time greater than pset_time?

So in Python, you're just going to replace these variables with their values. So is 8 greater than 15? And that's false, so perfect. And then one operation on Booleans derive as true. Drink is false.

I'm using the AND operator to figure out if I should drink and derive, and I'm going to print out false. So, perfect, people are getting it. Great job, guys.

Free Downloads

Video


Caption

  • English-US (SRT)