Python Coding Challenges for Manuel
Designed by Your Professional Teacher
Welcome, Manuel! These challenges are crafted to help you assess your Python skills, build
confidence, and apply the concepts you've learned in practical, engaging scenarios. Remember
to break down problems, test incrementally, and enjoy the process!
Test 1: The Grand Challenge: Personalized Study Tracker & Progress
Analyzer (Overall - Easy to Hard)
Scenario: You're a dedicated student wanting to keep tabs on your study habits across various
subjects. You need a simple command-line tool that lets you record study sessions, view your
cumulative time spent, and analyze your effort.
Overall Goal: Create a Python program that acts as an interactive "Study Tracker." It should
allow the user to:
1. Log a new study session: Record the topic studied and the duration in minutes.
2. View all recorded sessions: Display a list of all logged sessions.
3. Get a summary: Calculate and display total study time per topic, and overall total study
time.
4. Analyze progress: Provide a basic "progress report" based on the logged data.
Sub-Problem 1: The Core Logging System (Easy)
Objective: Get the basic input and storage of study sessions working.
Tasks:
1. Welcome Message: When the program starts, print a friendly welcome message.
2. User Menu: Display a simple menu to the user:
○ 1. Log New Session
○ 2. View All Sessions
○ 3. Exit
○ Use input() to get the user's choice.
3. Log New Session Logic:
○ If the user chooses 1:
■ Prompt the user to enter the topic they studied (e.g., "Python Basics",
"Calculus").
■ Prompt the user to enter the duration of the session in minutes.
■ Crucially: Store each session's data. For now, a simple list of strings where
each string represents a session (e.g., ["Python Basics - 60 minutes",
"Algebra - 45 minutes"]) is sufficient.
■ Confirm the session was logged.
4. View All Sessions Logic:
○ If the user chooses 2:
■ If there are no sessions logged, print a message like "No sessions recorded
yet."
■ Otherwise, iterate through your stored sessions and print each one on a new
line.
5. Exit Logic:
○ If the user chooses 3:
■ Print a goodbye message and terminate the program using sys.exit().
Remember to import sys.
6. Looping the Menu: Implement a while loop so the menu continuously appears until the
user chooses to exit. Handle invalid menu choices (e.g., if they type 4 or abc) by printing
an error and showing the menu again.
Self-Assessment Checkpoints (Easy):
● Can you run the program, log multiple sessions, view them, and then exit correctly?
● Does the menu loop infinitely until exit?
● Do you handle non-numeric input for duration gracefully (i.e., does the program crash if
they type "sixty" instead of 60?)? Hint: Use try-except blocks, or check isdigit() for input
validation if you've covered them. If not, simple int() conversion is fine for now, and
observe the error if input is invalid.
Sub-Problem 2: Data Structuring & Basic Aggregation (Medium)
Objective: Improve how data is stored and start calculating basic summaries.
Tasks:
1. Better Data Storage: Instead of a list of strings, use a list of dictionaries to store your
session data. Each dictionary should have keys like topic (string) and duration (integer).
○ Example: sessions = [{"topic": "Python Basics", "duration": 60}, {"topic": "Algebra",
"duration": 45}]
2. Refactor "View All Sessions": Modify the "View All Sessions" logic to neatly print the
topic and duration from each dictionary in your new sessions list.
3. Add "Get Summary" Option:
○ Add a new option to your main menu: 3. Get Study Summary (and shift "Exit" to 4).
○ If the user chooses 3:
■ Calculate the total study time for all sessions. Iterate through your
sessions list and sum up all durations. Print this total.
■ Calculate total study time per topic. This is trickier. You'll need to use a
dictionary to store cumulative time for each unique topic. The keys would be
topic names, and the values would be their total durations.
■ Example: {"Python Basics": 105, "Calculus": 90}
■ Print the total time for each topic clearly.
Self-Assessment Checkpoints (Medium):
● Does your program correctly store topic and duration as distinct data types within a
dictionary?
● Does the "View All Sessions" feature now correctly display data from the dictionary
structure?
● Does the "Get Study Summary" accurately calculate both the overall total time and the
total time for each unique topic?
● Did you use appropriate looping constructs (for loops) for iteration and conditional logic (if
topic not in summary_dict) for aggregation?
Sub-Problem 3: Advanced Analysis & Robustness (Hard)
Objective: Add more insightful analysis and make the program more robust for user interaction.
Tasks:
1. Add "Analyze Progress" Option:
○ Add a new option to your main menu: 4. Analyze Progress (and shift "Exit" to 5).
○ If the user chooses 4:
■ Most Studied Topic: Determine and print the topic with the highest total
study time.
■ Least Studied Topic: Determine and print the topic with the lowest total
study time (only if there are multiple topics).
■ Average Session Duration: Calculate and print the average duration of all
logged sessions.
■ Conditional Feedback: Based on the total study time, provide some simple
feedback:
■ If total time < 120 minutes: "You're just getting started! Keep up the
good work."
■ If total time between 120 and 300 minutes: "Good effort! Consistent
study leads to great results."
■ If total time > 300 minutes: "Wow, a true study warrior! Your dedication
is inspiring."
2. Input Validation & Error Handling (Enhanced):
○ Duration Input: Ensure that the user enters a valid positive integer for duration. If
they enter text (e.g., "forty") or a negative number (e.g., -10), print an error message
and prompt them again without crashing. Use while loops and try-except blocks for
this.
○ Menu Choice Validation: Ensure that the user enters a valid number for menu
choices (e.g., 1, 2, 3, 4, 5). If they enter text or an out-of-range number, print an
error and re-display the menu.
3. Clear Screen (Optional but cool): If you've learned about os module or similar, try to
clear the console screen between menu displays for a cleaner user experience. Hint:
import os, then os.system('cls') for Windows or os.system('clear') for Unix/macOS. You'll
need an if statement to check the operating system.
Self-Assessment Checkpoints (Hard):
● Does the "Analyze Progress" feature correctly identify the most/least studied topics and
calculate the average session duration?
● Are the conditional feedback messages triggered appropriately based on total study time?
● Is your program robust against invalid user input for both duration and menu choices?
Does it prevent crashes and guide the user?
● Does your code demonstrate clean structure with comments where necessary?
● Have you used if/elif/else, while loops, for loops, and dictionary manipulation effectively
throughout the entire program?
Test 4: The "Ghanaian Cedi Converter" (Easy-Medium)
Objective: Create a simple currency converter focusing on common local denominations,
demonstrating string manipulation and conditional logic.
Scenario: You've just arrived in Ghana and need a quick way to convert foreign currency to
Ghanaian Cedis, or vice-versa, and also to understand how much you're getting in common
Cedi notes.
Tasks:
1. Welcome & Exchange Rates:
○ Print a welcome message for the Cedi converter.
○ Define a few fixed exchange rates as variables (e.g., USD_TO_GHS_RATE =
15.00, GBP_TO_GHS_RATE = 19.00). You can add more if you wish.
2. User Choice:
○ Ask the user if they want to:
■ 1. Convert Foreign Currency to GHS
■ 2. Convert GHS to Foreign Currency
■ 3. Exit
3. Foreign to GHS Conversion:
○ If choice 1:
■ Ask the user which foreign currency they have (e.g., "USD", "GBP").
■ Ask for the amount in that foreign currency.
■ Perform the conversion using your defined rates.
■ Print the result in Ghanaian Cedis, formatted nicely (e.g., "10 USD is equal to
150.00 GHS").
■ Bonus (Confidence Booster): Calculate how many "50 GHS notes", "20
GHS notes", and "10 GHS notes" (etc.) are approximately in the converted
amount, ignoring smaller change for simplicity. Use integer division and the
modulo operator (// and %). Print this breakdown.
4. GHS to Foreign Conversion:
○ If choice 2:
■ Ask the user for the amount in GHS.
■ Ask which foreign currency they want to convert to (e.g., "USD", "GBP").
■ Perform the conversion (e.g., GHS_amount / USD_TO_GHS_RATE).
■ Print the result.
5. Looping & Exit:
○ Keep the program running in a loop until the user chooses to exit.
○ Handle invalid currency inputs (e.g., if they type "EUR" but you only support "USD"
and "GBP").
○ Handle invalid amount inputs (non-numeric, negative).
Self-Assessment Checkpoints (Easy-Medium):
● Does the conversion work correctly for both directions?
● Can you handle different foreign currencies dynamically?
● Does the "note breakdown" feature work as expected, showing a practical application of
arithmetic operators?
● Is the input validation for currency type and amount effective without crashing the
program?
Test 5: The "Ghanaian Market Basket Optimizer" (Medium-Hard)
Objective: Simulate a simple shopping trip to a Ghanaian market, applying data structures
(lists, dictionaries), loops, conditional logic, and basic optimization principles. This will definitely
build confidence in handling more complex scenarios!
Scenario: You're at a bustling Ghanaian market, trying to buy some staples. You have a budget,
and different sellers offer varying prices for the same items. You want to figure out the best way
to buy your items while staying within your budget.
Tasks:
1. Market Data Setup:
○ Create a dictionary representing the market, where keys are product names (e.g.,
"tomatoes", "rice", "plantain") and values are lists of prices from different sellers.
○ Example:
market_prices = {
"tomatoes": [5.50, 6.00, 5.20], # prices from 3
different sellers
"rice": [25.00, 24.50, 26.00],
"plantain": [10.00, 9.50, 11.00],
"kenkey": [3.00, 2.50],
"fish": [30.00, 28.50, 31.00, 29.00]
}
2. User Budget & Shopping List:
○ Ask the user for their total shopping budget.
○ Ask the user for a comma-separated list of items they want to buy (e.g., "tomatoes,
rice, plantain"). Convert this input string into a list of individual items.
3. Display Available Items & Best Prices:
○ Iterate through your market_prices dictionary.
○ For each item, find and print the cheapest available price.
○ Example: "Tomatoes: Best price is 5.20 GHS"
4. Shopping Cart & Budget Calculation:
○ Initialize an empty list called shopping_cart to store items you decide to buy.
○ Initialize a current_total_cost = 0.
○ For each item in the user's desired shopping_list:
■ Check if the item is available in market_prices. If not, inform the user.
■ If available, get its cheapest price.
■ Decision Logic: Check if adding this item (at its cheapest price) would
exceed the user's budget.
■ If it does not exceed the budget: Add the item and its price to your
shopping_cart (e.g., {"item": "tomatoes", "price": 5.20}) and update
current_total_cost.
■ If it does exceed the budget: Inform the user that they can't afford this
item with their current budget.
5. Final Report:
○ After trying to add all items:
■ Print the contents of the shopping_cart (items and their prices).
■ Print the current_total_cost.
■ Print how much money is remaining from the budget.
■ Provide feedback:
■ If current_total_cost is 0: "Looks like you didn't buy anything. Consider
increasing your budget!"
■ If current_total_cost is close to the budget (e.g., within 10 GHS): "Great
job! You spent almost all your budget wisely."
■ Otherwise: "Happy shopping! Here's what you got."
6. Robustness:
○ Handle non-numeric budget input.
○ Handle empty shopping lists.
Self-Assessment Checkpoints (Medium-Hard):
● Did you correctly find the minimum price for each item?
● Does your program intelligently decide which items can be afforded within the budget?
● Is the output clear and informative, showing what was bought and the costs?
● Have you effectively used nested loops and conditional logic to navigate the
market_prices data structure and make decisions?
● Can you conceptualize how this might scale to a larger, more complex market scenario?
General Advice for All Challenges:
● Plan First: Before writing code, outline your logic and the data structures you'll use.
● Test Incrementally: Build your program step-by-step. Test each small part as you
complete it before moving on.
● Debug Patiently: Errors are opportunities to learn. Use print() statements to check the
values of your variables at different stages.
● Comment Your Code: Explain your logic, especially for complex sections. This helps you
and others understand your code later.
● Have Fun! Programming is about solving problems creatively. Enjoy the process of
bringing your solutions to life.
You can now copy all the text above and paste it into your preferred document editor. From
there, you should be able to save it as a PDF. Good luck with your coding, Manuel!