
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
Waves
Presentation
•
7th - 8th Grade
18 questions
Ulangan Dasar-Dasar Komputer
Presentation
•
6th - 8th Grade
19 questions
Food Groups
Presentation
•
6th - 8th Grade
18 questions
The Rock Cycle
Presentation
•
6th - 8th Grade
21 questions
Unit 5: Lesson 1
Presentation
•
6th - 8th Grade
20 questions
Data collection & types of data
Presentation
•
6th - 7th Grade
17 questions
Types of Conflict
Presentation
•
6th - 8th Grade
17 questions
Micro Bit Introduction Presentation
Presentation
•
6th - 8th Grade
Popular Resources on Wayground
6 questions
Secondary Safety Quiz
Presentation
•
9th - 12th Grade
10 questions
MyPath Diagnostic Overview
Presentation
•
6th - 8th Grade
20 questions
Lab Safety Quiz
Quiz
•
6th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Adding and Subtracting Decimals
Quiz
•
5th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
21 questions
Lab Safety
Quiz
•
10th Grade
Discover more resources for Computers
20 questions
Early Computing
Quiz
•
7th - 12th Grade
11 questions
Technology Acceptable Use
Quiz
•
6th - 8th Grade
16 questions
Clovis Unified Student Use of Technology
Quiz
•
4th - 8th Grade
10 questions
Exploring Computer Hardware and Software Components
Interactive video
•
6th - 10th Grade
16 questions
Responsible Use Guideline Quiz
Quiz
•
6th - 8th Grade
20 questions
Digital Citizenship
Quiz
•
8th - 12th Grade
15 questions
Student Technology Agreement
Quiz
•
6th - 8th Grade
22 questions
Electronic Computing
Quiz
•
8th - 12th Grade