Find the lesson within this unit that you need to work with. Create a new section in your workbook with the same title as the lesson.
Read the Terms and Ideas sections of the Lesson, ask any questions that you have about the lesson content.
Read the Guided Note-taking and Learning Questions and Activities section. Copy them into your workbook.
Watch the video. When you see the symbol on the left << you need to make notes.
Then complete the Guided-Note-taking and Learning Questions and Activities.
Anything not completed in class must be completed at home before the next class.
Understanding data types is fundamental in computer science and programming. Data types define the kind of data a program can work with, such as numbers, text, or logical values, and determine how that data is stored and manipulated. This topic covers primitive data types, such as integers and strings, as well as compound data types, like arrays and records. It also explores how data is represented in binary form within computers and how programmers convert between data types to solve real-world problems. Mastering data types ensures efficient, accurate, and effective programming.
This lesson introduces primitive data types, which are the building blocks of all programs. You’ll learn how to identify and use these types effectively.
Key Terminology
Integer (int): A whole number, positive, negative, or zero (e.g., 5, -10).
Float (real): A number with a decimal point (e.g., 3.14, -2.7).
Boolean (bool): A value that can only be True or False.
Character (char): A single letter, number, or symbol (e.g., 'A', '7', '@').
String: A sequence of characters (e.g., "Hello", "12345").
Key Ideas
Primitive Data Types:
Integer: Used for counting or indexing.
Example in Python:
age = 25
Float: Used for precise calculations or measurements.
Example:
pi = 3.14159
Boolean: Used in decision-making or comparisons.
Example:
is_raining = False
Character: Represents single symbols or letters.
Example in Python (as a string of length 1):
grade = 'A'
String: Used for textual data or identifiers.
Example:
name = "Alice"
Guided Note-Taking
Use these headings for your notes:
Definition of Primitive Data Types.
Examples of Each Type (Integer, Float, Boolean, Character, String).
Practical Uses of Primitive Data Types.
Learning Questions & Activities
Write 3 examples of each primitive data type in Python.
Create a program that stores your name, age, and grade as variables and prints them.
Why is it important to understand data types? Write 3 bullet points.
This lesson introduces compound data types, which combine multiple pieces of information into one structure.
Key Terminology
Array: A collection of elements of the same type, stored in a fixed size. In Python these don't actually exist and we use Lists.
List: A collection of elements that can grow or shrink dynamically.
Record / Dictionary: A structure that groups related data of different types. In Python these are called dictionaries.
Key Ideas
Compound Data Types:
List: Dynamic; allows adding and removing elements.
Example:
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
Dictionary: Groups related fields of different data types (similar to a "row" in a table).
Example:
student = {"name": "Alice", "age": 16, "grade": "A"}
Guided Note-Taking
Use these headings for your notes:
Definition of Compound Data Types.
Characteristics of Arrays, Lists, and Records.
Advantages and Disadvantages of Each Type.
Learning Questions & Activities
Write a program to store and print the names and ages of 5 people using a list.
How is a record different from an array? Write 3 bullet points.
Create a table comparing arrays, lists, and records.
This lesson explains how data is stored in a computer using binary (1s and 0s).
Key Terminology
Binary: A base-2 number system (0 and 1) used by computers.
Bit: A single binary digit (0 or 1).
Byte: A group of 8 bits.
ASCII: A system for encoding characters as binary numbers.
Unicode: An encoding system for representing a wide range of characters.
Key Ideas
How Data Is Stored:
Computers are extremely dense collections of tiny switches that turn on and off. This is how they process and store information. The on and off values are represented as 0 and 1 as in binary.
Computers use binary to store all data (numbers, text, images, etc.).
Each data type has a specific binary representation.
Binary Representation Examples:
Numbers:
Decimal 5 → Binary 101.
Characters:
'A' in ASCII → Binary 01000001.
Images and Files:
Broken down into binary data for storage and processing.
Guided Note-Taking
Use these headings for your notes:
What Is Binary?
Examples of Binary Representation for Numbers and Characters.
Why Do Computers Use Binary?
Learning Questions & Activities
Convert the decimal numbers 7, 10, and 15 into binary.
Write 3 examples of characters and their binary (ASCII) representation.
Why is binary efficient for computers? Write 3 bullet points
This lesson focuses on how to change one data type into another in programming.
Key Terminology
Casting: Converting one data type into another.
Implicit Conversion: Automatic conversion performed by the programming language.
Explicit Conversion: Manual conversion by the programmer.
Key Ideas
Why Convert Data Types?
To perform operations on mixed data types. Many operations require a certain datatype otherwise will produce an error. For example, numbers inputed by a user through the keyboard will arrive in a program as a string, but if you need to do mathematical operations on these numbers they must be converted to an integer or float.
To prepare data for specific uses (e.g., storing numbers as strings as with phone numbers).
Examples of Type Conversion in Python:
String to Integer:
num_str = "10"
num_int = int(num_str)
print(num_int + 5) # Outputs: 15
Integer to Float:
num = 7
num_float = float(num)
Float to String:
pi = 3.14
pi_str = str(pi)
Guided Note-Taking
Use these headings for your notes:
Definition of Casting.
Examples of Implicit and Explicit Conversion.
Why Is Casting Useful?
Learning Questions
Why might you need to convert a number into a string? Write 3 reasons.
Practice converting between all the primitive data types.
Programming Activities
Write a program that asks the user for their birth year as a string. Convert this input into an integer and calculate their age. Assume the current year is 2025.
Instructions
Ask the user: "What is your birth year?" and store their response as a string. Use input() in your program.
Convert the birth year string into an integer.
Subtract the birth year from 2025 to calculate their age.
Print a message such as: "You are [age] years old."
Extension Task: Age Calculator with Months, Days, and Error Handling
Extend your program to calculate and display the user's age in months and days in addition to years. Use approximations (e.g., 1 year = 12 months, 1 year = 365 days).
Error Handling: Modify your program to handle invalid input gracefully using try / except. If the user enters non-numeric input (like letters or symbols), display a helpful error message and prompt them to try again.
Extra Challenge: Allow the user to input their birth month (1-12) and refine the age calculation for a more precise result.
Additional Programming Practice Questions
Activity 1: Add Two Numbers
Problem: Write a Python program to:
Ask the user for two numbers.
Convert the inputs into integers.
Add the numbers and print the result.
Activity 2: Calculate the Area of a Rectangle
Problem: Write a Python program to:
Ask the user for the width and height of a rectangle.
Convert the inputs into floats.
Calculate the area of the rectangle and print it.
Activity 3: List of Favorite Numbers
Problem:
Write a Python program to:
Ask the user for their three favorite numbers (one at a time).
Convert each number to an integer and add it to a list.
Print the list.
Activity 4: Concatenate a Name
Problem: Write a Python program to:
Ask the user for their first name and age.
Convert the age into a string.
Print a message saying, “Hello, [name]. You are [age] years old.”
Activity 5: Calculate an Average
Problem: Write a Python program to:
Ask the user for three test scores.
Convert the inputs into floats.
Calculate the average and print it.