Master Topic List for Chapters 1-5:
1. Displaying Output with the print() Function (C2)
2. Comments in Python (C2)
3. Variables and Data Types (int, float, str) (C2)
4. Reading Input from the Keyboard (input()) (C2)
5. Performing Calculations (Arithmetic Operators +, -, *, /, //, %, **)
(C2)
6. String Concatenation (+) (C2)
7. Formatted Output with F-strings (C2)
8. The if Statement (Single Alternative Decision Structure) (C3)
9. The if-else Statement (Dual Alternative Decision Structure) (C3)
10. The if-elif-else Statement (Multiple Conditions) (C3)
11. Comparing Strings Using Relational Operators (==, !=, <, >, <=,
>=) (C3)
12. Logical Operators (and, or, not) (C3)
13. Boolean Variables (True, False) (C3)
14. The while Loop (Condition-Controlled Loops) (C4)
15. The for Loop (Count-Controlled Loops) (C4)
16. Using range() in Loops (C4)
17. Calculating a Running Total Inside a Loop (C4)
18. Using a Sentinel Value to Control Loops (C4)
19. Input Validation Loops (Preventing Invalid User Input) (C4)
20. Nested Loops (C4)
21. Defining and Calling a Function (def function_name():) (C5)
22. Passing Arguments to Functions (C5)
23. Returning Values from Functions (return) (C5)
24. Scope of Variables: Local vs. Global Variables (C5)
25. Using the math Module (math.sqrt(), math.ceil(), math.floor())
(C5)
26. Generating Random Numbers with random.randint() (C5)
27. Storing Functions in Modules and Importing Them (import
module_name) (C5)
VERY Simple Examples of Those Topics:
All right, what follows are about as simple examples of each concept
as I can give you. Remember that these are examples of these steps at
their most basic. Do NOT make the mistake of thinking that if you can
work to JUST the level of these review notes that you are ready to sit
the exam or work in this field. These are only to help you get
started if you missed something in class.
Complete Review of All 27 Topics with Simple Examples
Each section includes:
- **Explanation** of the topic
- **Simple Example Code**
--1. `print()` Function
**Explanation:**
The `print()` function outputs text or variables to the console.
**Example:**
print("Hello, World!")
name = "Alice"
print("Hello,", name)
Displays text
Displays a variable
--2. Comments (``)
**Explanation:**
Comments are ignored by Python and used to describe code.
**Example:**
This is a single-line comment
"""
This is a multi-line comment
that spans multiple lines.
"""
print("Comments are ignored by Python")
This will print
--3. Variables & Data Types (`int`, `float`, `str`)
**Explanation:**
Variables store data, and Python determines their type dynamically.
**Example:**
name = "Alice"
String
age = 25
Integer
height = 5.6
Float
print(name, age, height)
--4. `input()` for User Input
**Explanation:**
The `input()` function takes user input as a string.
**Example:**
name = input("Enter your name: ")
print("Hello,", name)
--5. Arithmetic Operations (`+`, `-`, `*`, `/`, `//`, `%`, `**`)
**Explanation:**
Used for performing calculations.
**Example:**
a = 10
b = 3
print(a + b, a - b, a * b, a / b, a // b, a % b, a ** b)
--6. String Concatenation (`+`)
**Explanation:**
Combining strings using `+`.
**Example:**
first = "Hello"
second = "World"
print(first + " " + second)
--7. Formatted Output (f-strings)
**Explanation:**
Using `f""` to format strings.
**Example:**
name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old.")
--8. `if` Statement
**Explanation:**
Executes a block of code only if a condition is true.
**Example:**
age = 18
if age >= 18:
print("You are an adult.")
--9. `if-else` Statement
**Explanation:**
Executes one block if condition is true, another if false.
**Example:**
num = int(input("Enter a number: "))
if num > 0:
print("Positive")
else:
print("Not positive")
--10. `if-elif-else` Statement
**Explanation:**
Handles multiple conditions.
**Example:**
score = 85
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
else:
print("Grade: C")
--11. String Comparison (`==`, `!=`)
**Explanation:**
Comparing strings using relational operators.
**Example:**
word1 = "apple"
word2 = "orange"
if word1 == word2:
print("Words are the same")
else:
print("Words are different")
--12. Logical Operators (`and`, `or`, `not`)
**Explanation:**
Used for combining conditions.
**Example:**
age = 25
is_student = True
if age > 18 and is_student:
print("Eligible for student discount")
--13. Boolean Variables (`True`, `False`)
**Explanation:**
Stores true/false values.
**Example:**
is_raining = False
if not is_raining:
print("Go outside!")
--14. `while` Loop
**Explanation:**
Repeats while a condition is true.
**Example:**
count = 1
while count <= 5:
print(count)
count += 1
--15. `for` Loop
**Explanation:**
Repeats a fixed number of times.
**Example:**
for i in range(5):
print(i)
--16. `range()` Function
**Explanation:**
Generates a sequence of numbers.
**Example:**
for i in range(2, 10, 2):
print(i)
--17. Accumulator Pattern (Running Total)
**Explanation:**
Keeps a running sum of values.
**Example:**
total = 0
for i in range(1, 6):
total += i
print("Total:", total)
--18. Sentinel-Controlled Loops
**Explanation:**
Loops until a special value is entered.
**Example:**
while True:
num = int(input("Enter a number (-1 to stop): "))
if num == -1:
break
print("You entered:", num)
--19. Nested Loops
**Explanation:**
A loop inside another loop.
**Example:**
for i in range(3):
for j in range(3):
print(i, j)
--20. Defining and Calling Functions (`def`)
**Explanation:**
Functions help organize code.
**Example:**
def greet():
print("Hello!")
greet()
--21. Function Parameters and Return Values
**Explanation:**
Functions can accept input and return values.
**Example:**
def add(a, b):
return a + b
print(add(3, 4))
--22. `return` Statement
**Explanation:**
Returns a value from a function.
**Example:**
def square(num):
return num ** 2
print(square(5))
--23. Local Variables (No Global Variables)
**Explanation:**
Variables inside a function are local.
**Example:**
def example():
local_var = 10
print(local_var)
example()
--24. `math` Module (`sqrt()`, `ceil()`, `floor()`)
**Explanation:**
Provides mathematical functions.
**Example:**
import math
print(math.sqrt(16))
print(math.ceil(4.2))
print(math.floor(4.9))
--25. `random.randint()` for Random Values
**Explanation:**
Generates random numbers.
**Example:**
import random
print(random.randint(1, 100))
--26. Inventory Management with Dictionary
**Explanation:**
Using dictionaries to track stock.
**Example:**
inventory = {"Apple": 10, "Banana": 5}
inventory["Apple"] -= 1
print(inventory)
--27. File Handling (Extra Credit)
**Explanation:**
Saving data to a file.
**Example:**
with open("data.txt", "w") as file:
file.write("Hello, World!")
Practice Problems
These are my suggestions to practice with.
Chapter 2: Input, Processing, and Output
Topics Covered: print(), input(), variables, arithmetic operations,
formatted output
Exercise
Number
Exercise Name
Why It's Useful
2.7
Miles Per Gallon
Requires user input, calculations, and
formatted output
2.9
Tip, Tax, and Total
Works with numbers, calculations, and
formatted printing
2.12
Stock Transaction
Program
Uses multiple calculations, formatted
output
Chapter 3: Decision Structures and Boolean Logic
Topics Covered: if, if-else, if-elif-else, logical operators, Boolean
values, string comparison
Exercise
Number
Exercise Name
Why It's Useful
3.1
Day of the Week
Uses if-elif-else statements with
string comparisons
3.5
Mass and Weight
Requires mathematical conditions with
if logic
3.8
Change for a
Dollar Game
Requires if-else and arithmetic logic
3.13
Shipping Charges
Complex conditional logic with
multiple conditions
Chapter 4: Repetition Structures
Topics Covered: while, for, range(), running totals, nested loops,
input validation
Exercise
Number
Exercise Name
Why It's Useful
4.2
Bug Collector
Uses for loops and running totals
4.5
Average
Rainfall
Uses nested loops to track data
4.9
Tuition
Increase
Applies a loop for incremental
calculations
Exercise
Number
Exercise Name
Why It's Useful
4.10
Population
Uses loops and mathematical operations
Chapter 5: Functions
Topics Covered: Defining functions, passing arguments, returning
values, local vs. global variables
Exercise
Number
Exercise Name
Why It's Useful
5.1
Kilometer Converter
Requires defining and calling
functions
5.3
Areas of Rectangles
Uses multiple functions and
comparison logic
5.5
Property Tax
Requires calculations inside
functions
5.9
Rock, Paper,
Scissors Game
Uses functions, input validation, and
random.randint()
Practice Exam:
Project Requirements:
Display Welcome Message & Collect Customer Details
Create a method display_welcome() that prints a formatted welcome
message.
Create register_customer() to collect:
Full Name
Age (validate: must be numeric and greater than 0)
Email Address (validate: must contain '@')
Phone Number (validate: numeric)
Return customer details to main() for storage.
Display Product Catalog & Get Order Details
Create display_catalog() that prints a formatted product list (at
least 5 products with prices).
Create select_product() that:
Prompts the user for a product selection (validate: must be
from catalog).
Asks for quantity (validate: must be positive and available
in stock).
Return product details and quantity to main().
Process Order: Apply Discounts & Calculate Tax
Create calculate_discount(subtotal, quantity) that:
10% discount for buying more than 5 units.
Create calculate_tax(subtotal) that:
Apply 8.5% sales tax.
Return discount amount, tax, and final total to main().
Generate & Display Receipt
Create generate_receipt(customer, product, quantity, total,
discount, tax) that:
Prints a formatted receipt.
Generates a random order number.
Ensures all values are properly formatted (currency,
spacing).
Manage Inventory
Use a dictionary inside update_inventory(product, quantity) to
reduce stock after purchase.
Prevent purchase if requested quantity exceeds available
inventory.
Return updated inventory to main().
Provide Business Reporting
Create generate_report(password) for managers.
If correct password is entered, allow:
View total revenue
View current stock levels
Repeat Transactions & Exit System
Allow customers to buy multiple products in one session.
After each transaction, ask "Would you like to buy another
product? (Y/N)".
If N, exit gracefully.
Suggested Program Flow
Call display_welcome()
Call register_customer() → Store details
Call display_catalog()
Call select_product() → Validate input
Call calculate_discount() & calculate_tax()
Call generate_receipt()
Call update_inventory()
Allow repeat purchases via a loop
Call generate_report() (if requested)
Exit
Rules for Submission
All business logic must be inside functions (not main()).
No global variables! Pass data between functions via parameters and
return values.
Each function must contain docstrings explaining its purpose.
Handle invalid input gracefully.
Grading Criteria
Feature
Points
Self-documenting methods (docstrings)
10
No global variables
10
Input validation (age, quantity, email, etc.) 10
Use of functions and modular design
15
Error handling (no crashes)
10
Correct calculations (discounts, tax)
10
Properly formatted receipt output
10
Feature
Points
Inventory tracking & update
10
Repeat transactions (looping)
10
Business report feature
5
Total
100
Final Notes
Think like a software developer. Structure your code cleanly.
Comment your methods! Self-explanatory function names help but
docstrings are required.
No hardcoding. If a user enters incorrect data, ask again instead of
failing.
Test before submitting. If your program crashes, it will lose major
points.
Python Programming Exam – Test Cases & Expected Outputs
Test Case Format
Each test case includes:
**Inputs** (What the user enters)
**Expected Outputs** (What the program should return)
**Error Handling Cases** (What happens if invalid data is entered)
--Test Case 1: Welcome Message & Customer Registration
**Inputs:**
[System starts]
Enter your name: Alice Johnson
Enter your age: 28
Enter your email: alice@example.com
Enter your phone number: 5551234567
**Expected Output:**
Welcome to TechEdge Solutions!
Your reliable tech store.
Customer Registration:
Name: Alice Johnson
Age: 28
Email: alice@example.com
Phone: 5551234567
**Error Handling Cases:**
| Invalid Input | Expected Behavior |
|--------------|------------------|
| Age = `"abc"` | Ask again until a valid number is entered |
| Age = `"-5"` | Reject negative numbers, ask again |
| Email = `"aliceexample.com"` | Reject missing `"@"`, ask again |
| Phone = `"55a123"` | Reject non-numeric input |
--Test Case 2: Display Product Catalog & Select Product
**Inputs:**
[System displays catalog]
Enter product number: 3
Enter quantity: 2
**Expected Output:**
Available Products:
1. Keyboard - $50 (10 in stock)
2. Mouse
- $30 (8 in stock)
3. Monitor
- $200 (5 in stock)
4. Headset
- $80 (12 in stock)
5. USB Drive - $25 (15 in stock)
Selected: Monitor
Quantity: 2
**Error Handling Cases:**
| Invalid Input | Expected Behavior |
|--------------|------------------|
| Product = `"7"` | Ask again (must be between 1-5) |
| Quantity = `"abc"` | Ask again (must be numeric) |
| Quantity = `"8"` (if only 5 are in stock) | Reject, ask again |
--Test Case 3: Discount & Tax Calculation
**Inputs:**
Product: Monitor ($200 each)
Quantity: 6
**Expected Output:**
Subtotal: $1200
Discount Applied: 10% (-$120)
Sales Tax (8.5%): $91.80
Final Total: $1,171.80
**Error Handling Cases:**
| Invalid Input | Expected Behavior |
|--------------|------------------|
| Quantity = `"-3"` | Reject negative values, ask again |
--Test Case 4: Order Confirmation & Receipt Generation
**Inputs:**
Confirm Order? (Y/N): Y
**Expected Output:**
Order Confirmed! Receipt:
Order 4357
Customer: Alice Johnson
Product: Monitor (x6)
Subtotal: $1200
Discount: -$120
Sales Tax: $91.80
Final Total: $1,171.80
**Error Handling Cases:**
| Invalid Input | Expected Behavior |
|--------------|------------------|
| Input = `"X"` | Ask again (must be Y/N) |
--Test Case 5: Inventory Update After Purchase
**Initial Stock Levels:**
Monitor: 5 in stock
**Inputs:**
Enter product number: 3
Enter quantity: 5
Confirm Order? (Y/N): Y
**Expected Output:**
Transaction completed. Remaining inventory:
Monitor: 0 in stock
**Error Handling Cases:**
| Invalid Input | Expected Behavior |
|--------------|------------------|
| Tries to buy `"6"` monitors (when only `5` are in stock) | Reject,
ask again |
--Test Case 6: Admin Reports (Revenue & Inventory Tracking)
**Inputs:**
Enter manager password: admin123
**Expected Output:**
Business Report:
Total Sales Revenue: $1,171.80
Remaining Inventory:
- Keyboard: 10
- Mouse: 8
- Monitor: 0
- Headset: 12
- USB Drive: 15
**Error Handling Cases:**
| Invalid Input | Expected Behavior |
|--------------|------------------|
| Password = `"wrongpass"` | Reject, deny access |
--Test Case 7: Multi-Purchase Workflow & Loop Handling
**Inputs:**
Enter product number: 1
Enter quantity: 2
Confirm Order? (Y/N): Y
Would you like to buy another product? (Y/N): Y
Enter product number: 2
Enter quantity: 1
Confirm Order? (Y/N): Y
Would you like to buy another product? (Y/N): N
**Expected Output:**
First Order:
- Product: Keyboard (x2)
- Total: $100 + tax
Second Order:
- Product: Mouse (x1)
- Total: $30 + tax
Final Receipt Generated.
Thank you for shopping with TechEdge Solutions!
**Error Handling Cases:**
| Invalid Input | Expected Behavior |
|--------------|------------------|
| `"abc"` in product number | Ask again (must be numeric) |
| `"N"` at final prompt | Gracefully exit |
--Test Case 8: Random Order Number Generation
**Inputs:**
Confirm Order? (Y/N): Y
**Expected Output:**
Order Confirmed! Receipt:
Order [Random Number between 1000-9999]
*(Each time, the order number should be different.)*
--Test Case 9: Edge Cases for Repeated Transactions
| Scenario | Expected Behavior |
|----------|------------------|
| Buying `"6"` of a product that has `"5"` in stock | Reject, ask
again |
| Entering `"0"` for quantity | Reject, ask again |
| Entering an **email without `@`** | Reject, ask again |
| Entering a **negative age** | Reject, ask again |
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )