Branching

Flash and JavaScript are required for this feature.

Download the video from iTunes U or the Internet Archive.

Description: This in-class question demonstrates how conditional branching works 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 we have x is going to be whatever number the user types in, y is going to be whatever number the user types in. First thing I'm going to check is if x is equal to y. So if we type in x is 0 and y is 5, 0 is not equal to 5, so we're not even going to consider what's in this code block.

Then we're going to check the next one-- if 0 is less than 5-- and that's true. So this is the very first conditional that evaluates to true, so we're just going to print x is smaller. And I think that's what's being dragged down here. Awesome.

Free Downloads

Video


Caption

  • English-US (SRT)