Python Numbers Slides
Computing Foundations for a Digital Age
Lesson 4.2 • 45 Min
Integers, Floats &
Percentages in Python
Using Python to Work With Real Data
Today's Target
I can use integers and floats in Python to calculate totals, averages, and percentages.
Warm-Up Activity Think & Share
What Do You Remember?
warmup.py
students = 28
average_rating = 4.6
01
Which variable stores an integer?
02
Which variable stores a float?
03
What is the core difference between the two?
Record your initial reasoning in Part 1 of your lab sheet before class discussion!
Core Concepts Data Types
Review: Integer vs. Float
int (Integer) Whole Numbers
- Represents exact whole quantities
- Contains no decimal point
- Examples: 15, 0, -3, 30
float (Floating Point) Decimals
- Represents fractional or continuous values
- Always contains a decimal point
- Examples: 4.5, 3.14, 0.25, 100.0
Key Idea: Survey data and real-world analytics constantly combine counts (integers) and measurements or ratios (floats).
Prediction Challenge Type Awareness
Why Data Types Matter
Test this snippet:
age = input("How old are you? ")
print(age + 1)
What happens when we run this?
If you enter 15 at the prompt, what will Python do?
• Will it print 16?
• Will it print 151?
• Will Python give an error?
Test it in your notebook right now to discover Python's reaction — record what happened in Part 1!
Type Casting Converting Input
Converting Input to Numbers
1. Whole Number Input → int()
age = int(input("How old are you? "))
2. Decimal Number Input → float()
height = float(input("How tall are you in feet? "))
When to use int()
Counts of people, votes, questions, items, or whole years.
When to use float()
Prices, measurements, ratings, percentages, or calculated averages.
Remember: Python works from inside out — it grabs input text first, then turns it into a number!
Code Along #1
Open Google Colab / Replit
Class Attendance Counter
Type this in your notebook:
students = 30
absent = 4
present = students - absent
print(present)
Worksheet Step
✍️ Predict the output on Part 2 before pressing Run!
Discussion Questions
• Which variables are integers?
• What calculation is Python performing?
Run the code: What value did Python output? Did it produce an integer or a float?
Python Toolkit Math Operators
Basic Math Operators
Addition
10 + 5
-
Subtraction
30 - 4
*
Multiplication
5 * 8
/
Division
20 / 4
Observation Challenge: In Python, what data type does division (/) always produce, even when numbers divide evenly?
Remember: Asterisk * is multiplication, and slash / is division.
The Big Formula Percentages
From Counts to Percentages
Universal Percentage Formula
Percentage = Part ÷ Whole × 100
total = 30
yes_votes = 18
percent_yes = yes_votes / total * 100
print(percent_yes)
Quick Inquiry:
Before running this code, what will Python calculate?
Will the printed result be an integer or a float? Why?
Run it in your notebook: What exact number prints out?
Code Along #2
Survey Data Simulation
Scenario: 20 out of 32 students in class said they prefer a longer lunch.
total = 32
yes_votes = 20
no_votes = total - yes_votes
yes_percent = yes_votes / total * 100
no_percent = no_votes / total * 100
print(yes_percent)
print(no_percent)
Worksheet Tasks (Part 2)
-
Predict each percentage before running
-
Run in Colab and record actual results
-
Add them together: do they total ~100%?
Compare your actual numbers with a neighbor: do your percentages make mathematical sense?
Data Presentation Precision vs Clarity
Messy Decimals
percent = 17 / 23 * 100
print(percent)
Terminal Output: 73.91304347826086
Question 1:
Is this calculation wrong or broken?
Question 2:
Would you show this number to a principal or client in a report?
Turn to your partner: How would a human normally write this percentage?
Python Toolkit Built-in Functions
Using round()
percent = round(17 / 23 * 100, 1)
print(percent)
The Anatomy
round(number, decimals)
• 1st input: the value you want to round
• 2nd input: how many decimal places to keep
Predict the Output
What will Python print when you pass 1 as the second argument?
What would change if you passed 2 or 0?
Test it in your notebook right now to see the formatted output!
Data Calculations Averages
Working With Averages
Scenario: Four students rate an app activity from 1 to 5: 4, 5, 3, 4.
rating1 = 4
rating2 = 5
rating3 = 3
rating4 = 4
average = (rating1 + rating2 + rating3 + rating4) / 4
print(average)
Think & Discuss:
Why might an average be a float even when all individual ratings are integers?
Notice the parentheses ()! Why are they required around the sum?
Predict what Python outputs: Will it show 4 or 4.0? Run it to find out!
Code Along #3
Interactive User Input
User-Entered Survey Data
total = int(input("How many people answered the survey? "))
yes_votes = int(input("How many answered yes? "))
yes_percent = yes_votes / total * 100
print("Percent who answered yes:", yes_percent)
⚡ Next-Level Upgrade Challenge
Where and how should you add round() to keep 1 decimal place?
Try modifying line 3 in your notebook and record your new line in Part 2 of your lab sheet!
Test your code with numbers that produce messy decimals (e.g., Total = 19, Yes = 13)!
Debugging Challenge #1
Spot The Glitch
Why Does This Fail?
Broken Snippet:
price = input("Enter the price: ")
tax = price * 0.07
Worksheet Part 3
1. Why does Python throw an error?
2. What data type is price right now?
3. How would you rewrite line 1 to fix the error?
Diagnose the bug with a partner and write your corrected code on Part 3 of your lab sheet!
Debugging Challenge #2
Logic vs. Syntax
Is the Code Broken?
yes = 18
total = 30
percent = yes / total
print(percent)
Investigate:
1. Does Python crash or throw an error?
2. Run it: What value prints to the screen?
3. Does that number match what humans call a percentage?
What math step is missing from line 3? Record the corrected calculation on your lab sheet!
Independent Lab
12 Minutes
Survey Percentage Calculator
Core Requirements
- ☑ At least 3 numeric variables
- ☑ Use
int() or float() for input
- ☑ Perform at least 2 calculations
- ☑ Calculate at least 1 percentage
- ☑ Use
round() to clean decimals
- ☑ Clearly print formatted results
Optional Stretch Goal
Calculate and print both the "yes" and "no" percentages, and verify that they add up to 100%!
Lab Sheet Guide
Check off each requirement on Part 4 of your lab sheet as you complete and test your code!
Raise your hand or pair-check with your neighbor when you have tested your calculator!
Looking Ahead Computing Foundations → Data Science
Connection to Data Science
Later in our Data Science unit, we will analyze large datasets with thousands of survey responses.
1. Read Data
Convert raw inputs into ints and floats
2. Percentages
Identify trends, proportions, and voting shares
3. Averages
Find central tendencies in rating scales
4. Summarize
Round and present clean metrics to decision makers
Today's skills are the computational math tools behind modern data analysis!
Exit Ticket
5 Minutes • Complete on Worksheet
Show What You Know
Question 1
What is the difference between an integer and a float?
Question 2
Why might you use float() instead of int() when capturing user input?
Question 3
Write the formula for calculating a percentage in Python.
Question 4
What does round(number, 1) do?
Turn in your lab sheet before you leave class today!
Python Numbers Lab Worksheet
Computing Foundations for a Digital Age
Lab Sheet: Integers, Floats & Percentages
Name:
Date:
Period:
Score:
Target Use ints & floats in Python to calculate totals, averages, and percentages.
Part ÷ Whole × 100
1
Part 1: Data Types Exploration
students = 28 Warm-Up Item A
Data Type: int float
Why?
average_rating = 4.6 Warm-Up Item B
Data Type: int float
Why?
Predict the Bug (Slide 4)
Code: age = input(...) ; print(age + 1)
What crashes? Why?
Write Your Own Real Data Variables
Integer var:
Float var:
2
Part 2: Code Along Lab Tracking
Code Along #1: Attendance Subtraction present = students - absent
1. My Prediction
2. Python Actual Output
3. Output Type
int float
Code Along #2: Survey Data (20 out of 32 prefer longer lunch) yes_percent & no_percent
Before Running: Predict Results
Predicted yes_percent:
Predicted no_percent:
After Running: Terminal Outputs
Actual yes_percent:
Actual no_percent:
Sum Check: Do they total approximately 100%?
Yes (Sum = 100.0) No
Code Along #3: User-Entered Survey with round() int(input()) + round(..., 1)
Upgraded Rounding Formula Line
Write your code using round():
Test Results from Colab / Replit
Your Inputs: Total = ____ , Yes = ____
Formatted Output:
Turn page over for Part 3 (Debugging), Part 4 (Mini Project), and Exit Ticket →
Computing Foundations • Unit: Data & Types
Page 2: Debugging & Application
3
Part 3: The Code Doctor (Debugging)
Challenge #1: Price Input Bug
price = input("Enter the price: ")
tax = price * 0.07
What is wrong with this code?
How do you fix line 1?
Challenge #2: Incomplete Logic
yes = 18; total = 30
percent = yes / total; print(percent)
Why isn't 0.6 a true percentage?
Write the corrected calculation:
4
Part 4: Mini Survey Calculator Project
Python Numbers Teacher Key
Teacher Facilitation Guide & Master Answer Key
Python Numbers: Teacher Key & Guide
Lesson Duration: 45 Min Computing Foundations
Recommended 45-Minute Lesson Pacing
Warm-Up & Concepts 10m
Slides 1–5: int vs float, type casting from input()
Guided Code Alongs 15m
Slides 6–13: counts, percentages, rounding & averages
Debugging & Lab 15m
Slides 14–16: 2 challenges + Mini Survey Calculator
Wrap-Up & Exit 5m
Slides 17–18: Data science connection & exit ticket
✓
Part 1 Solutions: Data Types Exploration
students = 28 KEY
Correct Type: int (Integer)
Explanation: Represents a discrete, whole count of people. You cannot have partial human beings in a classroom.
average_rating = 4.6 KEY
Correct Type: float (Floating-point decimal)
Explanation: Contains a decimal point representing a continuous average measurement on a rating scale.
Slide 4 Bug Explanation Key
TypeError Explanation: input() always returns a string (str). In Python, using + between a string and an integer causes a crash because Python cannot add text and numbers together.
Exemplar Student Variables
Integer: total_books = 14 or goal_laps = 5
Float: ticket_price = 12.50 or gpa = 3.85
✓
Part 2 Solutions: Code Along Tracking
Code Along #1: Attendance Subtraction Output: 26 (int)
Teacher Note: Highlight that subtraction between two integers (30 - 4) always remains an integer. No decimals are created during addition or subtraction of ints.
Code Along #2: Survey Percentages (20 / 32) yes: 62.5% | no: 37.5%
Calculations: yes_percent = 20 / 32 * 100 → 62.5
no_percent = 12 / 32 * 100 → 37.5
Sum & Type Check: Sum = 100.0 (Exactly 100%). Both outputs are floats because Python division (/) always produces a float.
Code Along #3: Interactive Survey with round() round(yes_votes / total * 100, 1)