MTH1W • CODING LESSON 1

Coding in Python

Loading Python… You can read the lesson while this finishes.
Task 1 of 12

Display a message

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Keep the first line. Add a second line that displays I am learning Python with [your name]. Replace [your name] with your own name.
Output
Press Run.
Task 2 of 12

Text or calculation?

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Keep the original two lines. Add two new lines: display 20 - 8 as text, then have Python calculate 20 - 8. Your program should have four lines.
Output
Press Run.
Task 3 of 12

Use operations

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Add another line of code that displays the result of 10 divided by 5. Python uses / for division. The new output will be 2.0.
Output
Press Run.
Task 4 of 12

Order matters

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Add a new first line that displays Ready!. The four messages must appear in this order: Ready!, First, Second, Third.
Output
Press Run.
Task 5 of 12

Store a value

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Add a new line that displays number multiplied by 5. Use the name number. Do not type the number 6 again.
Output
Press Run.
Task 6 of 12

Variable, constant, equation

1. Read, predict, and run

A variable is a name that stores a value.
A constant is a number that does not change.
An equation says two amounts are equal.

Here, tickets is a variable and 3 is a constant.
The equation is tickets + 3 = 7.
Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Change the name of the variable from tickets to apples. Keep the value 4 and the constant 3. Display apples, then apples + 3, then 3. Do not type 7.
Output
Press Run.
Task 7 of 12

Calculate in steps

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Add one more calculation step: multiply answer by 2 and store it in final_answer. Then change the print line to display final_answer. The output must be 22.
Output
Press Run.
Task 8 of 12

Complete the code

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Complete all three blanks so the program triples number, subtracts 4, and displays the final answer. The output must be 11.
Output
Press Run.
Task 9 of 12

Challenge 1: Like terms

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Keep x = 4. Add two new print lines that test 4x + 2x and 6x. The added lines must both display 24.
Output
Press Run.
Task 10 of 12

Challenge 2: Distributive property

1. Read, predict, and run

Read the code. Type your prediction, then press Run.

Output
Press Run.

3. Now modify it

Keep x = 5. Add two new print lines that test 3(x + 2) and 3x + 6. The added lines must both display 21.
Output
Press Run.
Task 11 of 12

Check Your Understanding

Answer all six questions, then select Mark Answers. You need all six correct to continue.

1. What does print() do?
2. What is the output of print("8 + 2")?
3. Which symbol means multiply in Python?
4. What does number = 7 do?
5. If number = 3, double = number * 2, and answer = double + 4, what is printed?
6. In tickets = 6 and print(tickets + 3), which statement is correct?
Task 12 of 12

Make your own code!

Create a Python program with more than 5 non-empty lines of code. The program can use any skills from this lesson, but the final displayed output must be 50. Your code must run without errors.
Output
Press Run.