0% found this document useful (0 votes)
6 views

Python Skills Lesson 1 Arithmetric

The document outlines fundamental programming skills in Python, focusing on inputs, outputs, arithmetic operations, and data types. It includes examples of code errors, correct usage of print statements, and basic arithmetic rules. Additionally, it covers data type casting and functions for mathematical operations such as rounding and calculating powers and roots.

Uploaded by

pcji.ngg
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python Skills Lesson 1 Arithmetric

The document outlines fundamental programming skills in Python, focusing on inputs, outputs, arithmetic operations, and data types. It includes examples of code errors, correct usage of print statements, and basic arithmetic rules. Additionally, it covers data type casting and functions for mathematical operations such as rounding and calculating powers and roots.

Uploaded by

pcji.ngg
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Objectives

• Use inputs, outputs, arithmetic and string


handling
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python

Starter activity Answers


• Find 3 errors in the following code:
name = input("Enter employee name: ")
age = int(input("Enter their age: "))
wage = float(input("Hourly wage: "))
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python

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

Inputs and outputs


• Printing a message to the screen in Python is pretty
straightforward

print("Hello, world!")
print("Hello" , name)
print("Hello " + name)
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python

Inputs and outputs

print(name, "owes £", amount)


>>> Dave owes £ 3.75

print(name + " owes £" +


str(amount))
>>> Dave owes £3.75
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python

Inputs and outputs


print("When did you turn", age)
date = input()
• or
date = input("When did you turn “ ,age)
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python

Inputs and outputs


• If your input is a number then make the data type
clear

name = input("Enter employee name:


")
age = int(input("Enter their age:
"))
wage = float(input("Hourly wage:
"))

print(name)
print(age)
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python

Data Types and casting


• In Python you only need to know four data types:
String – A piece of text
str() or a mixture of
letters and numbers
Integer – A whole number
int()
Float – A number with
a decimal point
float() known as Real in
some languages
Boolean – True or False
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

answer = (num1 + num2) * num2


print(answer)
36
Fundamentals
Preparation: Regular expressions
Tackling Controlled
Practical programming
Assessment
skills in Python
in Python

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

Roots and powers


Examples of roots and powers include:
# Powers
5 ** 2 # 52
25
5 ** 3 # 53
125
# Roots
25 ** (1/2) # square root
5
125 ** (1/3) # cube root 3√125 5
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: "))

You might also like