Python Skills Lesson 1 Arithmetric
Python Skills Lesson 1 Arithmetric
Starter activity
• Find 3 errors in the following code:
name = int("Enter employee name: ")
age = input("Enter their age: ")
wage = float(input("Hourly wage: ))
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python
print("Hello, world!")
print("Hello" , name)
print("Hello " + name)
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python
print(name)
print(age)
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python
Arithmetic
• The main arithmetic operators are straightforward
num1 = 9
num2 = 3
print(num1 + num2)
12
print(num1 - num2)
6
print(num1 * num2)
27
7 //
print(num1 /
2 # floor division
num2)
3 3.0
7 % 2 # modulo (remainder) 1
Dividing two numbers always gives a float
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python
Arithmetic rules
• BIDMAS/BODMAS rules still apply
num1 = 9
num2 = 3
answer = num1 + num2 * num2
print(answer)
18
Arithmetic functions
• There are several useful functions:
pi = 3.1415927
num1 = round(pi)
3
num2 = round(pi, 3)
3.142
# Given that 7 / 2 = 3.5
7 // 2 # floor division
3
7 % 2 # modulo (remainder)
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python
Plenary
Find 3 errors in the following code:
name = int("Enter employee name: ")
age = input("Enter their age: ")
wage = float(input("Hourly wage: ))
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python
Plenary Answers
Find 3 errors in the following code:
name = input("Enter employee name: ")
age = int(input("Enter their age: "))
wage = float(input("Hourly wage: "))