
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
21 questions
Under the Hood of Computer
Presentation
•
7th Grade
19 questions
Rock Cycle
Presentation
•
6th - 8th Grade
23 questions
6-Dars Python: Integer va arifmetik amallar
Presentation
•
6th - 8th Grade
20 questions
ICT1 - Communications
Presentation
•
6th - 8th Grade
19 questions
Hardware
Presentation
•
5th - 8th Grade
20 questions
Circulatory System Review
Presentation
•
6th - 8th Grade
20 questions
Sentence Structure
Presentation
•
6th - 8th Grade
20 questions
Scale Factor Lesson
Presentation
•
6th - 8th Grade
Popular Resources on Wayground
10 questions
GPA Lesson
Presentation
•
9th - 12th Grade
7 questions
Albert Einstein
Quiz
•
3rd Grade
31 questions
Bridge A Review
Quiz
•
3rd Grade
6 questions
Blue Sue and Red Ruth
Quiz
•
3rd Grade
8 questions
(Day12 HW) Inverse Trig Ratios
Quiz
•
9th Grade
20 questions
Summer Geometry QUIZ (Week3)
Quiz
•
9th Grade
16 questions
Theme Practice
Quiz
•
7th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade