If-else example

This example shows you how an if-else statement works.

Use the Set button to set an initial value for n, and notice how line 2 of the code changes to reflect the value you chose. If the box under the Next button is checked when n is set on line 2, then all occurrences of n in the code will also be replaced with the value of n in order to make the comparisons more explicit.

Then use the Next button to step through the code one line at a time. The current line of code is highlighted so you can see where you are in the process, and the box to the right of the code shows you the current value of n (it will briefly turn to red when the value changes). n is set to None when you start out, because its value doesn't get set until line 2.

The output from the print statements will appear below the code.

n =

Variables
n

Replace the variable n in the code with the value of n

Output:

        

Hit the Set button at the top of the page to start over.