# SHAD UBC 2018: Python Lessons

Watch the videos for each lesson, then do the exercises for that lesson.

## Lesson 1: Python as a Calculator

### EXERCISES

• Configure the up & down arrow keys for the `history-previous` & `history-next` actions in IDLE.
• Use IDLE to determine:
• 17 + 89
• 100 - 23
• 12 * 45
• 100 / 4

## Lesson 2: Variables

EXERCISES

In IDLE:

• Create a variable that stores your age (in years).
• Calculate the square of your age. For example, if your age is `10`, the square of your age is `10 * 10 = 100`.
• Create a variable named `x`. Give it the value `4`.
• Create a variable named `y`. Give it the value `5`.
• Calculate `x` times `y`.
• Change the value of `x` to 7.
• Calculate `x` times `y`.

## Lesson 3: Simple Data Types

EXERCISES

In IDLE:

• Create a variable that stores your name.
• Create another variable that stores your name duplicated seven times (for example, `KyleKyleKyleKyleKyleKyleKyle`).

## Lesson 4: Lists

EXERCISES

In IDLE:

• Create a variable that stores a list of three animals.
• Display the first, second and third animal in your list.
• See what happens when you try to display a fourth animal in your list.

## Lesson 5: Script Mode

EXERCISE

• Create a script file that calculates and displays the square of your age.

## Lesson 6: User Input & Type Conversion

EXERCISE

• Create a script file that:
• Asks the user for their age and then displays the square of their age.

## Lesson 7: Conditional Execution

EXERCISE

• Create a script file that asks the user for their grade. If the user is in grade 12, display "I hope you graduate!". Otherwise, display "I hope you do well in high school!".

## Lesson 8: Repetition with While Loops

EXERCISE

• Create a script file that does a countdown. Ask the user for a number and then count down from that number to zero before displaying "Blast off!".
• See what happens when the user enters a value that isn't a number.

## Lesson 9: Repetition with For Loops

EXERCISES

• Create a script file that displays the numbers from 0 to 7 followed by their square. For example, the first three rows should be `0 0`, `1 1`, and `2 4`.

## Lesson 10: Functions without Return Values

EXERCISE

• Create a script file that repeatedly asks the user for a number. If the number is zero, the program ends. Otherwise, the program displays the number and its square. Use a function to print each number and its square.

## Lesson 11: Functions with Return Values

EXERCISE

• Create a script file that repeatedly asks the user for a number. If the number is zero, the program ends. Otherwise, the program displays whether the number is even or odd. HINT: Create a function that uses `%`. Use IDLE to figure out what `%` does.

## Lesson 12: Modules

EXERCISE

• Create a script file that repeatedly asks the user for a number. If the number is zero, the program ends. Otherwise, the program displays the square root of the number.