Lesson 1 · Unit 01
Values and expressions
Numbers, text, print and arithmetic
What you practise
- Numbers and text,
print, arithmetic and its order,//,%and**, text in quotes, a program runs one line at a time
Try a question from this lesson
Pick one
This is a whole program, one line long. What do you think it shows on the screen when it runs?
print(2 + 3)Correct answer
5
Why
Python first works out what is inside the brackets: 2 + 3 is 5. Then print shows that result on the screen. It shows the answer, not the sum you typed.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Your first program
A program is a list of instructions. Python runs them one line at a time, from the top down.
print(...) is an instruction that shows a value on the screen. A value is a piece of data, such as the number 10.
Anything after a # is a comment: a note for people. Python skips it.
print(10) # shows 10
print(4 + 6) # also shows 10Concept
Operators
+, -, * and / are operators: they combine two values into a new one.
/ always gives a number with a decimal point. // divides and throws the remainder away. % gives only the remainder. ** is "to the power of".
print(8 / 2) # 4.0
print(7 // 2) # 3
print(7 % 2) # 1
print(2 ** 3) # 8Concept
Strings
Text inside quote marks is called a string. Single or double quotes both work, as long as the string ends with the kind it started with.
With strings, + joins and * repeats.
Give print several values with commas between them, and it shows them on one line with spaces.
print("Hi " + "Ada") # Hi Ada
print("ha" * 3) # hahaha
print("Total:", 5 + 1) # Total: 69 more exercises in the app
- 3× type the answer
- 2× multiple choice
- 1× fill the blanks
- 1× match the pairs
- 1× true or false
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.