Python Basics Practice: Report Card, Shopping Cart and Password Checker from a Prompt
Three use cases (a report card, a shopping cart receipt, a password strength checker) turned into prompts, then one possible result for each, read line by line and checked against the requirements.
What you will learn
- Find what a use case leaves open before you write a prompt
- Turn a use case into a Role, Context, Task, Format prompt with clear requirements
- Read a dict loop, an if/elif grade ladder, continue and boolean flags in real programs
- Check program output against each requirement, including a row that looks missing
Before you start
- Python Conditionals and Loops
- Looping Over Real Data in Python
- Prompting Fundamentals for Code
Imagine you call a baker and say just one thing: make me a cake. You'll get a cake, but the baker had to guess the flavour, the size and what goes on top. Think for a moment before you call, answer those three, and the same baker makes the cake you had in mind.
An AI tool is a lot like that baker. So in this practice you'll take three small use cases, find what's missing, write the prompt, and then read what comes back against what you asked for. The three are a student report card, a shopping cart receipt and a password strength checker.
One rule for all three: do not use functions, imports or classes. Plain Python statements only, the ones you already know, so you can read every line you get back.
Use case 1: a student report card
Here's the kind of statement you get as a developer: a teacher needs a simple program that takes a list of students with their scores, assigns letter grades, computes the class average, and prints a neatly formatted report card.
It sounds clear, but look closer. What score makes an A, and what makes a B? How many students, stored how? Which columns is "neatly formatted"? Anything else to print? Paste it as it is and the tool will assume all of these answers, and they may not be what you wanted. So answer them:
- Store five students and their scores in a dictionary.
- Grades by range: A is 90 and above, B 80, C 70, D 60, F below 60.
- Work out the class average, and the highest and lowest scorer.
- Format the report in columns with f-strings.
Try writing the prompt yourself before reading on. Here's one possible prompt:
You are helping a Python beginner. A teacher wants a report card for a small class. Create a student report card in Python. Store five students with scores from 0 to 100 in a dictionary. Grade A is 90 and above, B is 80, C is 70, D is 60, and F is below 60. Print the class average, the highest and the lowest scorer. Show neat columns of name, score and grade using f-strings. Do not use functions, imports or classes.
Saying "in Python" matters, or you might get an HTML page. And notice what you didn't say: no variable names, no step-by-step logic. Define what really matters to you, like the rules, the input and the output, and leave the tool some room.
One possible result
Your AI tool's answer will look different, and that's fine. Read this one:
students = {
"Asha": 92,
"Ben": 78,
"Chitra": 85,
"Dev": 64,
"Esha": 47,
}
total = 0
highest_name = ""
highest_score = -1
lowest_name = ""
lowest_score = 101
print(f"{'Name':<10}{'Score':>7}{'Grade':>7}")
print("-" * 24)
for name, score in students.items():
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
elif score >= 60:
grade = "D"
else:
grade = "F"
print(f"{name:<10}{score:>7}{grade:>7}")
total += score
if score > highest_score:
highest_score = score
highest_name = name
if score < lowest_score:
lowest_score = score
lowest_name = name
average = total / len(students)
print("-" * 24)
print(f"Class average: {average:.1f}")
print(f"Highest: {highest_name} ({highest_score})")
print(f"Lowest: {lowest_name} ({lowest_score})")
Name Score Grade
------------------------
Asha 92 A
Ben 78 C
Chitra 85 B
Dev 64 D
Esha 47 F
------------------------
Class average: 73.2
Highest: Asha (92)
Lowest: Esha (47)
The loop takes each name and score with items() and walks down the grade ladder. Ben's 78 isn't 90 or 80 but is above 70, so he gets a C. On every pass the score is added to total: 92, 170, 255, 319, 366. Divided by 5, that's 73.2.
For the highest, the code starts at -1 so Asha's 92 takes the spot straight away, and nobody beats her. For the lowest it starts at 101; Asha takes it first, then Ben, then Dev, and finally Esha with 47.
Now the part that matters most: the program ran, but that doesn't mean you're done. Five rows, yes. Chitra's 85 is a B, which is right. 366 / 5 is 73.2, matching. Highest Asha, lowest Esha. No def, import or class. Every requirement has its answer.
Use case 2: a shopping cart receipt
An online store needs a program that processes a shopping cart, applies a discount based on item quantity, calculates tax, and prints a formatted receipt. What's missing? How much discount, at what quantity? What tax rate? What about an item with quantity zero? The answers: five items in a list of dictionaries, 10% off at quantity 3 or more, 8% tax, money to two decimals, and one item with quantity 0 skipped using continue.
You are helping a Python beginner. A small online store needs a receipt for one cart. Create a shopping cart receipt in Python. Store five items as a list of dictionaries with name, price and quantity. Give one item a quantity of 0 and skip it using continue. Apply a 10 percent discount when the quantity is 3 or more. Print the subtotal, 8 percent tax and the grand total. Show each item with its line total, money to two decimal places. Do not use functions, imports or classes.
cart = [
{"name": "Notebook", "price": 4.50, "quantity": 3},
{"name": "Pen", "price": 1.20, "quantity": 5},
{"name": "Lamp", "price": 18.00, "quantity": 1},
{"name": "USB cable", "price": 6.00, "quantity": 0},
{"name": "Backpack", "price": 32.50, "quantity": 2},
]
subtotal = 0
print(f"{'Item':<12}{'Price':>8}{'Qty':>5}{'Total':>10}")
print("-" * 35)
for item in cart:
if item["quantity"] == 0:
continue
line_total = item["price"] * item["quantity"]
note = ""
if item["quantity"] >= 3:
line_total = line_total * 0.90
note = " 10% off"
subtotal += line_total
print(
f"{item['name']:<12}{item['price']:>8.2f}"
f"{item['quantity']:>5}{line_total:>10.2f}{note}"
)
tax = subtotal * 0.08
grand_total = subtotal + tax
print("-" * 35)
print(f"{'Subtotal':<25}{subtotal:>10.2f}")
print(f"{'Tax (8%)':<25}{tax:>10.2f}")
print(f"{'Grand total':<25}{grand_total:>10.2f}")
Item Price Qty Total
-----------------------------------
Notebook 4.50 3 12.15 10% off
Pen 1.20 5 5.40 10% off
Lamp 18.00 1 18.00
Backpack 32.50 2 65.00
-----------------------------------
Subtotal 100.55
Tax (8%) 8.04
Grand total 108.59
The Notebook is 4.50 times 3, so 13.50; quantity 3 is enough for the discount, so it drops to 12.15. The Lamp has quantity 1, so no discount. The USB cable has quantity 0, so continue sends the loop straight back to the top: no line total, no row, and the subtotal doesn't move. continue means skip the rest for this item and carry on with the next.
Checking the receipt
Count the rows. You asked for five items, and there are four. A problem? The missing one is the USB cable, with quantity 0, and you asked for it to be skipped. Exactly right. Next, the edge of the discount: the Notebook, with exactly 3, got 10% off; the Backpack, with 2, didn't. Always check the edge like this. A count that looks wrong may be just what you asked for, and you can only tell if you know your requirements.
Use case 3: a password strength checker
A tool analyses a password character by character, checks it against some criteria, and gives a strength rating. Which criteria, and how do checks become a rating? Our answer: five checks (at least 8 characters, an uppercase letter, a lowercase letter, a digit, a special character), one point each, 5 points is Strong, 3 or 4 Medium, lower is Weak. These are only the checks picked for this exercise, with a made-up password. It's practice with loops and flags, not advice about passwords.
You are helping a Python beginner. This is a learning exercise. Use a made-up password in a variable. Create a password strength checker in Python. Go through the password character by character. Check for at least 8 characters, an uppercase letter, a lowercase letter, a digit and a special character. Give one point per check. Rate 5 points as Strong, 3 or 4 as Medium, below 3 as Weak. Show each check as passed or not, then the score and the rating. Do not use functions, imports or classes.
password = "Maple#Tree7"
specials = "!@#$%^&*()-_+="
has_upper = False
has_lower = False
has_digit = False
has_special = False
for ch in password:
if ch.isupper():
has_upper = True
elif ch.islower():
has_lower = True
elif ch.isdigit():
has_digit = True
elif ch in specials:
has_special = True
long_enough = len(password) >= 8
checks = {
"At least 8 characters": long_enough,
"Has an uppercase letter": has_upper,
"Has a lowercase letter": has_lower,
"Has a digit": has_digit,
"Has a special character": has_special,
}
score = 0
print(f"Password: {password}")
for label, passed in checks.items():
if passed:
score += 1
print(f" [x] {label}")
else:
print(f" [ ] {label}")
if score == 5:
rating = "Strong"
elif score >= 3:
rating = "Medium"
else:
rating = "Weak"
print(f"Score: {score} / 5")
print(f"Rating: {rating}")
Password: Maple#Tree7
[x] At least 8 characters
[x] Has an uppercase letter
[x] Has a lowercase letter
[x] Has a digit
[x] Has a special character
Score: 5 / 5
Rating: Strong
Four flags start as False. The loop takes one character at a time: M is uppercase, so has_upper flips; a flips has_lower; the hash isn't a letter or digit but is in specials, so has_special flips; the final 7 flips has_digit. The length is a separate check with no loop: 11 is at least 8. All five answers go in a dictionary, and a second loop adds a point for each True. Five checks printed, the score matches the boxes, the rating follows the rule.
Quick recap
| Use case | What you had to decide | Python you read |
|---|---|---|
| Report card | grade ranges, storage, columns, extra stats | dict, items(), if/elif ladder, running max/min |
| Shopping cart | discount rule, tax rate, zero quantity | list of dicts, continue, f-string widths |
| Password checker | criteria and rating rules | loop over a string, boolean flags, a dict of checks |
These programs are small, but when an application grows things get harder, so the fundamentals and the practice really count.
Try it yourself
Pick one use case and write the prompt yourself, without copying these. Run what comes back and check every requirement, using the habit from Checking AI-written Python code.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Python for AI: The Five Tools You Actually Need
The small part of Python that carries most AI code: dicts and JSON, typed functions with a dataclass, comprehensions and f-strings, environment variables for keys, and try/except for replies that are not JSON. Three standard-library scripts on four support tickets.
Thinking Like a Python Architect in an AI-First World
Coding is laying bricks; architecting is deciding how the pieces fit. A two-line average function shows why someone still has to understand the code an AI tool writes.
Your First Python Program: print, Comments, sep and end
Five tiny files: print and quotes, top-to-bottom order, # comments, several values with sep and end, and the SyntaxError one missing quote causes. Every output is from a real run.
Set Up PyCharm for Python: Install, First Project and First Run
Install PyCharm, create a Pure Python project, and understand the two words that confuse beginners: the interpreter (the cook) and .venv (the project's own shelf). Then run a file and read the exit code.
