
Python Data types and arithmetic
Presentation
•
Computers
•
6th - 8th Grade
•
Medium
N Ellis
Used 27+ times
FREE Resource
16 Slides • 9 Questions
1
Data Type and Arithmetic
2
• Understand the importance of using correct data
types: string, integer or float
• Use the int, float and round functions
• Understand how to use assignment
statements correctly
• Perform arithmetic using the BIDMAS rule
• Write a program involving input, calculation
and output
Objectives
3
Data types and arithmetic
Introduction to Python
The input statement
• In the last lesson, you used two statements: one to
give the user a prompt, and a second to accept
user entry
print(" Enter your name: ")
name = input()
• You can combine these two statements to give a
prompt and accept input:
name = input(" Enter your name: ")
4
Multiple Choice
5
Data types and arithmetic
Introduction to Python
Concatenating text
• Concatenating means “joining together”
• A plus sign (+) is used to join two strings
• What will this Python code print?
age = 14
print ("Kumar " + " Ahmad are " +
str(age) + "years old")
• Caution: It won’t print quite correctly! Try it out…
6
Data types and arithmetic
Introduction to Python
What does this program do?
• Look at the code below and describe what each
line does
#Animal
animal = input("Enter the name of an animal: ")
description = input("How would you describe a " + animal + "? ")
print ("A ",animal," is ",description)
print("You will find it under ",animal[0]," in the dictionary")
7
Data types and arithmetic
Introduction to Python
Data types
• String holds alphanumeric data as text
• Integer holds whole numbers
• Float holds numbers with a decimal point
• Boolean holds either ‘True’ or ‘False’
8
Data types and arithmetic
Introduction to Python
The importance of data types
• Python will always assign a data type of string when
data is entered using the input() function
mynumber = input("Enter a number")
print (mynumber + mynumber)
• What do you think happens?
• Try it!
• Convert the data type: mynumber = int(mynumber)
• Where would you put this line?
9
Data types and arithmetic
Introduction to Python
Defining variable data types
• Python automatically assigns a data type to a
variable
• You can override this to manually define or change
the data type using:
•str()
str(age)
•int()
int(goals_scored)
•float() float(share_price)
• This is called Casting
10
Data types and arithmetic
Introduction to Python
Choosing data types
Data
Example
Data Type
Code
Age
14
Integer
int(age)
Shoe Size
6.5
Float
Price
14.99
Postcode
Height
Quantity in Stock
Telephone Number
11
Multiple Choice
12
Multiple Choice
13
Multiple Choice
14
Multiple Choice
15
Multiple Choice
What is an integer?
A number
A positive number
A whole number
A number with a decimal part
16
Multiple Choice
Which of these is a floating point number?
3
3.0
7
5.6
17
Data types and arithmetic
Introduction to Python
Assignment statements
• Assignment statements assign a value to a variable
• If the variable doesn’t already exist, it’s created
Examples:
name ="Jo"+" Smith"
number = 10
number =input("Enter a number")
18
Data types and arithmetic
Introduction to Python
BIDMAS
• The order of arithmetic operations matters
• Brackets , Indices, Division and Multiplication,
Addition and Subtraction
19
Data types and arithmetic
Introduction to Python
Arithmetic operators
Arithmetic
Operator
Example
Output
Addition
+
2 + 10
12
Subtraction
-
9 – 6
3
Multiplication
*
5 * 4
20
Division
/
5 / 2
2.5
Floor division
//
7 // 2
3
Remainder
%
7 % 3
1
20
Multiple Choice
Which of these is the symbol for divide in python?
÷
/
>
21
Fill in the Blanks
Type answer...
22
Data types and arithmetic
Introduction to Python
Sleep calculator
• Create a program to calculate how many hours per
week you sleep
• Try this code and find the problem!
hourspernight =input("How many hours per night do
you sleep? ")
hoursperweek = hourspernight * 7
print ("You sleep",hoursperweek,"hours per week")
23
Data types and arithmetic
Introduction to Python
Sleep calculator
• Extend the problem to find the total number of hours
spent sleeping in a month
• Assume an average of 4.35 weeks per month
hourspernight = input("How many hours per night do
you sleep? ")
hoursperweek =float(hourspernight) * 7
print ("You sleep",hoursperweek,"hours per week")
hourspermonth =hoursperweek * 4.35
print("You sleep",hourspermonth,"hours per month")
24
Data types and arithmetic
Introduction to Python
Sleep calculator
• Now find the equivalent number of days per month
you sleep for!
25
Data types and arithmetic
Introduction to Python
Rounding
hourspermonth = 228.37499999999997
round(hourspermonth) = 228
round(hourspermonth,2) = 228.37
hourspernight = input("How many hours per night do you sleep? ")
hoursperweek = float(hourspernight) * 7
print ("You sleep",hoursperweek,"hours per week")
hourspermonth = hoursperweek * 4.35
hourspermonth = round(hourspermonth)
print (“\nYou sleep",hourspermonth,"hours per month")
Data Type and Arithmetic
Show answer
Auto Play
Slide 1 / 25
SLIDE
Similar Resources on Wayground
19 questions
Exploring Operator Blocks in Makeblock
Presentation
•
6th - 8th Grade
21 questions
History of Computers
Presentation
•
6th - 8th Grade
20 questions
Identifying Participles
Presentation
•
6th - 8th Grade
20 questions
Rocks and Rock Cycle
Presentation
•
6th - 8th Grade
21 questions
Pertemuan 2 Informatika Ganjil 2024
Presentation
•
7th Grade
18 questions
Continental Drift
Presentation
•
6th - 8th Grade
21 questions
Structures in Poetry & Drama
Presentation
•
6th - 8th Grade
Popular Resources on Wayground
15 questions
Grade 3 Simulation Assessment 1
Quiz
•
3rd Grade
22 questions
HCS Grade 4 Simulation Assessment_1 2526sy
Quiz
•
4th Grade
16 questions
Grade 3 Simulation Assessment 2
Quiz
•
3rd Grade
19 questions
HCS Grade 5 Simulation Assessment_1 2526sy
Quiz
•
5th Grade
17 questions
HCS Grade 4 Simulation Assessment_2 2526sy
Quiz
•
4th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
24 questions
HCS Grade 5 Simulation Assessment_2 2526sy
Quiz
•
5th Grade
20 questions
Math Review
Quiz
•
3rd Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials
Interactive video
•
6th - 10th Grade
18 questions
Company Logos
Quiz
•
6th - 8th Grade
10 questions
Exploring Cybersecurity Techniques and Threats
Interactive video
•
6th - 10th Grade
9 questions
Health
Interactive video
•
6th - 8th Grade
18 questions
history of video games
Quiz
•
6th Grade