Python Lesson 25: Mini Projects

🐍 Python CourseLesson 25 of 26 · 96% complete

The best way to learn is by building. Here are 3 complete mini projects that use everything you’ve learned. Build each one yourself — then check the solution.

Project 1: Quiz Game

# A terminal quiz with 5 questions
import random

questions = [
    {"q": "What is 2 ** 10?", "a": "1024"},
    {"q": "What function removes the last item from a list?", "a": "pop"},
    {"q": "What does len() return?", "a": "length"},
    {"q": "What keyword starts a function?", "a": "def"},
    {"q": "What type is True and False?", "a": "bool"}
]

random.shuffle(questions)
score = 0

print("Welcome to the Python Quiz!")
print("-" * 30)

for i, q in enumerate(questions, 1):
    answer = input(f"Q{i}: {q['q']} ").strip().lower()
    if answer == q["a"]:
        print("Correct! +1 point")
        score += 1
    else:
        print(f"Wrong. Answer was: {q['a']}")

print(f"\nFinal Score: {score}/5")
if score == 5:
    print("Perfect! You are a Python expert!")
elif score >= 3:
    print("Good job! Keep practicing.")
else:
    print("Keep studying! You will get there.")

Project 2: Contact Book

import json
import os

FILE = "contacts.json"

def load(): 
    if os.path.exists(FILE):
        with open(FILE) as f: return json.load(f)
    return {}

def save(contacts):
    with open(FILE, "w") as f: json.dump(contacts, f, indent=2)

def add_contact(contacts):
    name = input("Name: ").strip()
    phone = input("Phone: ").strip()
    email = input("Email: ").strip()
    contacts[name] = {"phone": phone, "email": email}
    save(contacts)
    print(f"{name} added!")

def search(contacts):
    name = input("Search name: ").strip()
    if name in contacts:
        c = contacts[name]
        print(f"{name}: {c['phone']} | {c['email']}")
    else:
        print("Not found.")

contacts = load()
while True:
    print("\n1=Add  2=Search  3=List  4=Quit")
    choice = input("Choice: ")
    if choice == "1": add_contact(contacts)
    elif choice == "2": search(contacts)
    elif choice == "3": 
        for name, info in contacts.items():
            print(f"{name}: {info['phone']}")
    elif choice == "4": break

Project 3: Daily Todo with JSON Storage

import json
import os
from datetime import date

TODO_FILE = "todos.json"

def load_todos():
    if os.path.exists(TODO_FILE):
        with open(TODO_FILE) as f: return json.load(f)
    return []

def save_todos(todos):
    with open(TODO_FILE, "w") as f: json.dump(todos, f, indent=2)

todos = load_todos()

while True:
    print(f"\nTodo List - {date.today()}")
    for i, t in enumerate(todos):
        status = "DONE" if t["done"] else "    "
        print(f"  [{status}] {i+1}. {t['task']}")
    
    print("\na=Add  d=Done  r=Remove  q=Quit")
    cmd = input("Command: ").strip().lower()
    
    if cmd == "a":
        task = input("New task: ").strip()
        todos.append({"task": task, "done": False})
    elif cmd == "d":
        n = int(input("Mark done (number): ")) - 1
        todos[n]["done"] = True
    elif cmd == "r":
        n = int(input("Remove (number): ")) - 1
        todos.pop(n)
    elif cmd == "q":
        save_todos(todos)
        print("Saved. Goodbye!")
        break
    
    save_todos(todos)

🏋️ Practice Task

Pick ONE project and build it yourself from scratch WITHOUT looking at the solution. Time yourself. When done, compare your solution to the one above. Note what you did differently.

💡 Hint: Start with the simplest one (Quiz Game). Write each piece step by step. If stuck, re-read the relevant lesson.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *