Control Flow¶

Ha Khanh Nguyen (hknguyen)

1. if Statement¶

• The if statement checks a condition that, if True, evaluates the code in the block that follows:
• Note that a colon : is needed at the if statement, before the code block begins.
• And the code block after : MUST BE INDENTED.
• Jupyter Notebook automatically indent the code after a colon :.
• If you want to manually indent a line of code, use TAB! Please avoid using the spacebar.

2. elif Statement¶

• An if statement can be optionally followed by one or more elif blocks.

3. else Statement¶

• The else statement is used a catch-all block if all of the conditions above it are False.
• If any of the condition is True, no further elif or else blocks will be reached.

4. Exercises¶

Exercise 1: We are given 2 numbers stored in variables a and b. Write a program to print the number with the larger value.

Exercise 2: We are given 2 strings s1 and s2. If one is contained in the other, print "One is a substring of the other!". Otherwise, print "They are distinct strings!"