🏗️ PHASE 1 · MINI PROJECTS

Build Real
Python Programs

You've learned the foundations. Now apply everything — variables, strings, operators, input, and output — to build 4 actual programs from scratch.

4
PROJECTS
~2h
BUILD TIME
5
CONCEPTS USED
🟢
BEGINNER
LESSON 1
Introduction
LESSON 2
Variables & Types
LESSON 3
Strings & Text
LESSON 4
Operators
LESSON 5
Input & Output
🧮
PROJECT 01 OF 04
Smart Calculator
A fully interactive calculator that takes two numbers and an operator from the user, handles all arithmetic operations, and produces a clean formatted result with error checking.
input() arithmetic operators if/elif/else f-strings type conversion
✅ Features
  • Supports +, -, *, /, //, %, ** operators
  • Detects division by zero and warns user
  • Shows integer result when no decimal needed
  • Clean formatted output with separators
  • Handles unknown operators gracefully
🧠 Concepts Used
  • float(input()) for numeric input
  • if/elif/else for operator routing
  • Comparison: divisor != 0
  • f-string formatting :,.6g
  • String strip() for operator input
smart_calculator.py
PYTHON
# ══════════════════════════════════════════════
#   Smart Calculator — Phase 1 Project 1
#   Concepts: input, operators, if/elif, f-strings
# ══════════════════════════════════════════════

print("=" * 38)
print("        🧮  SMART CALCULATOR")
print("  Operators: + - * / // % **")
print("=" * 38)

# ── Get input ────────────────────────────────
num1 = float(input("\nFirst number  : "))
op   = input("Operator      : ").strip()
num2 = float(input("Second number : "))

# ── Calculate ────────────────────────────────
result = None
error  = ""

if op == "+":
    result = num1 + num2
elif op == "-":
    result = num1 - num2
elif op == "*":
    result = num1 * num2
elif op == "/":
    if num2 != 0:
        result = num1 / num2
    else:
        error = "❌ Cannot divide by zero."
elif op == "//":
    if num2 != 0:
        result = num1 // num2
    else:
        error = "❌ Cannot floor-divide by zero."
elif op == "%":
    if num2 != 0:
        result = num1 % num2
    else:
        error = "❌ Cannot modulo by zero."
elif op == "**":
    result = num1 ** num2
else:
    error = f"❌ Unknown operator '{op}'. Use: + - * / // % **"

# ── Display result ───────────────────────────
print("\n" + "─" * 38)
if error:
    print(f"  {error}")
else:
    # Format: show int if whole number, else decimal
    fmt = int(result) if result == int(result) else f"{result:.6g}"
    print(f"  {num1:g} {op} {num2:g} = ", fmt)
print("─" * 38)
smart_calculator.py — sample run
======================================
🧮 SMART CALCULATOR
Operators: + - * / // % **
======================================
First number : 144
Operator : **
Second number : 0.5
──────────────────────────────────────
144 ** 0.5 = 12
──────────────────────────────────────
Extension challenge
Add a loop so the calculator keeps running until the user types quit. You'll learn loops in Phase 2 — try to add this after Lesson 8.
🌡️
PROJECT 02 OF 04
Unit Converter
Convert between the most common everyday units — temperature, length, and weight. The user picks a category and direction, enters a value, and gets an instant precise result.
arithmetic operators f-string formatting if/elif/else .lower() validation
✅ Features
  • Temperature: °C ↔ °F ↔ K
  • Length: km ↔ miles, m ↔ ft
  • Weight: kg ↔ lbs, g ↔ oz
  • Menu-driven with numbered choices
  • Invalid input handled cleanly
🧠 Concepts Used
  • Constants for conversion factors
  • Nested if/elif for category + direction
  • float(input()) with descriptive prompts
  • :.4f and :.2f precision formatting
  • .strip().lower() for robust input
unit_converter.py
PYTHON
# ══════════════════════════════════════════════
#   Unit Converter — Phase 1 Project 2
#   Concepts: operators, f-strings, if/elif
# ══════════════════════════════════════════════

# ── Conversion constants ─────────────────────
KM_TO_MILES  = 0.621371
M_TO_FT      = 3.28084
KG_TO_LBS    = 2.20462
G_TO_OZ      = 0.035274

# ── Menu ─────────────────────────────────────
print("=" * 40)
print("        🌡️  UNIT CONVERTER")
print("=" * 40)
print("  1 → Temperature (°C / °F / K)")
print("  2 → Length      (km / miles / m / ft)")
print("  3 → Weight      (kg / lbs / g / oz)")
print("=" * 40)

choice = input("Choose category (1/2/3): ").strip()

# ── Temperature ──────────────────────────────
if choice == "1":
    print("\n  a) °C → °F    b) °F → °C")
    print("  c) °C → K     d) K  → °C")
    sub = input("  Choose (a/b/c/d): ").strip().lower()
    val = float(input("  Enter value    : "))

    if   sub == "a": res, unit = val * 9/5 + 32,    "°F"
    elif sub == "b": res, unit = (val - 32) * 5/9, "°C"
    elif sub == "c": res, unit = val + 273.15,       "K"
    elif sub == "d": res, unit = val - 273.15,       "°C"
    else: res, unit = None, "unknown"

# ── Length ────────────────────────────────────
elif choice == "2":
    print("\n  a) km → miles  b) miles → km")
    print("  c) m  → ft     d) ft    → m")
    sub = input("  Choose (a/b/c/d): ").strip().lower()
    val = float(input("  Enter value    : "))

    if   sub == "a": res, unit = val * KM_TO_MILES,       "miles"
    elif sub == "b": res, unit = val / KM_TO_MILES,       "km"
    elif sub == "c": res, unit = val * M_TO_FT,           "ft"
    elif sub == "d": res, unit = val / M_TO_FT,           "m"
    else: res, unit = None, "unknown"

# ── Weight ────────────────────────────────────
elif choice == "3":
    print("\n  a) kg → lbs  b) lbs → kg")
    print("  c) g  → oz   d) oz  → g")
    sub = input("  Choose (a/b/c/d): ").strip().lower()
    val = float(input("  Enter value    : "))

    if   sub == "a": res, unit = val * KG_TO_LBS,  "lbs"
    elif sub == "b": res, unit = val / KG_TO_LBS,  "kg"
    elif sub == "c": res, unit = val * G_TO_OZ,    "oz"
    elif sub == "d": res, unit = val / G_TO_OZ,    "g"
    else: res, unit = None, "unknown"

else:
    print("❌ Invalid category. Please choose 1, 2, or 3.")
    res = None

# ── Output ────────────────────────────────────
if res is not None:
    print(f"\n  ✅ Result : {val:g} → {res:.4f} {unit}")
💡
Inline if on one line
Notice the pattern if sub=="a": res, unit = ... — Python allows a single statement on the same line as if. It's compact but only good for very short assignments. For multiple lines, always use proper indentation.
🧠
PROJECT 03 OF 04
Python Quiz App
A 5-question multiple-choice quiz that tests Python knowledge, tracks the score, shows right/wrong feedback per question, and prints a grade at the end — all without loops.
if/elif/else comparison operators augmented += string .lower() f-strings
✅ Features
  • 5 questions, A/B/C/D options each
  • Instant right/wrong feedback per answer
  • Score tracked with augmented assignment
  • Letter grade assigned at the end
  • Case-insensitive answer checking
🧠 Concepts Used
  • input().strip().lower() for answers
  • score += 1 for counting correct answers
  • if/elif chain for grade assignment
  • Chained comparisons: 0 <= score <= 5
  • Percentage: score / 5 * 100
quiz_app.py
PYTHON
# ══════════════════════════════════════════════
#   Python Quiz App — Phase 1 Project 3
#   Concepts: if/elif, comparison, +=, f-strings
# ══════════════════════════════════════════════

score = 0
TOTAL = 5

print("=" * 42)
print("        🧠  PYTHON QUIZ  — Phase 1")
print("     Answer each question with a/b/c/d")
print("=" * 42)

# ── Q1 ───────────────────────────────────────
print("\nQ1. What does type(3.14) return?")
print("  a) <class 'int'>    b) <class 'float'>")
print("  c) <class 'str'>    d) <class 'double'>")
ans1 = input("  Your answer: ").strip().lower()
if ans1 == "b":
    print("  ✅ Correct! 3.14 has a decimal — it's a float.")
    score += 1
else:
    print("  ❌ Incorrect. Answer: b — 3.14 is a float.")

# ── Q2 ───────────────────────────────────────
print("\nQ2. What does 17 % 5 return?")
print("  a) 3       b) 3.4")
print("  c) 2       d) 0")
ans2 = input("  Your answer: ").strip().lower()
if ans2 == "c":
    print("  ✅ Correct! 17 = 5×3 + 2, remainder is 2.")
    score += 1
else:
    print("  ❌ Incorrect. Answer: c — 17 % 5 = 2.")

# ── Q3 ───────────────────────────────────────
print("\nQ3. Which creates a valid f-string?")
print("  a) f\"Hello {name}\"    b) \"Hello {name}\".format()")
print("  c) $\"Hello {name}\"    d) \"Hello\" + {name}")
ans3 = input("  Your answer: ").strip().lower()
if ans3 == "a":
    print("  ✅ Correct! f-strings start with f before the quote.")
    score += 1
else:
    print("  ❌ Incorrect. Answer: a — f\"Hello {name}\" is correct.")

# ── Q4 ───────────────────────────────────────
print("\nQ4. What does input() ALWAYS return?")
print("  a) int      b) float")
print("  c) str      d) Depends on what user types")
ans4 = input("  Your answer: ").strip().lower()
if ans4 == "c":
    print("  ✅ Correct! input() ALWAYS returns a string.")
    score += 1
else:
    print("  ❌ Incorrect. Answer: c — always a str.")

# ── Q5 ───────────────────────────────────────
print("\nQ5. What does \"Python\"[::-1] return?")
print("  a) \"Python\"    b) \"Pyt\"")
print("  c) \"nohtyP\"    d) Error")
ans5 = input("  Your answer: ").strip().lower()
if ans5 == "c":
    print("  ✅ Correct! [::-1] reverses the string.")
    score += 1
else:
    print("  ❌ Incorrect. Answer: c — reversed is 'nohtyP'.")

# ── Final score ───────────────────────────────
pct = score / TOTAL * 100
if   pct == 100: grade, msg = "A+", "🏆 Perfect! You're a Phase 1 master."
elif pct >=  80: grade, msg = "A",  "⭐ Excellent work!"
elif pct >=  60: grade, msg = "B",  "👍 Good — review any you missed."
elif pct >=  40: grade, msg = "C",  "📚 Re-read Phase 1 lessons."
else:              grade, msg = "F",  "🔄 Start Phase 1 from the beginning."

print(f"""
{'═'*42}
  FINAL SCORE : {score}/{TOTAL}  ({pct:.0f}%)
  GRADE       : {grade}
  {msg}
{'═'*42}""")
Extension challenge
Add more questions by copy-pasting the Q block pattern. Later in Phase 2, you'll store all questions in a list of dictionaries and loop through them — a much cleaner approach that scales to 100 questions.
📊
PROJECT 04 OF 04
Report Card Generator
Enter marks for 5 subjects and get a beautifully formatted report card with totals, percentage, letter grade, GPA, subject ranking, pass/fail per subject, and personalised feedback.
arithmetic comparison logical operators f-string formatting input + type conversion
✅ Features
  • 5 subjects with individual pass/fail
  • Total, percentage, GPA (4.0 scale)
  • Letter grade A+ to F
  • Highest and lowest subject detected
  • Personalised feedback message
🧠 Concepts Used
  • Multiple inputs with float(input())
  • Built-in max() and min() functions
  • Ternary: "Pass" if mark >= 50 else "Fail"
  • Nested if/elif for grade + GPA
  • :5.1f width formatting for alignment
report_card.py
PYTHON
# ══════════════════════════════════════════════
#   Report Card Generator — Phase 1 Project 4
#   Concepts: all Phase 1 skills combined
# ══════════════════════════════════════════════

print("═" * 44)
print("       📊  REPORT CARD GENERATOR")
print("      Enter marks out of 100 per subject")
print("═" * 44)

student = input("\nStudent name : ").strip().title()
roll    = input("Roll number  : ").strip()
print()

math    = float(input("Mathematics  : "))
english = float(input("English      : "))
science = float(input("Science      : "))
urdu    = float(input("Urdu         : "))
cs      = float(input("Computer Sc. : "))

# ── Calculations ─────────────────────────────
subjects = [math, english, science, urdu, cs]
total    = math + english + science + urdu + cs
pct      = total / 500 * 100
highest  = max(subjects)
lowest   = min(subjects)
all_pass = math >= 50 and english >= 50 and \
           science >= 50 and urdu >= 50 and cs >= 50

# Letter grade
if   pct >= 95: grade, gpa = "A+", 4.0
elif pct >= 85: grade, gpa = "A",  4.0
elif pct >= 75: grade, gpa = "B+", 3.5
elif pct >= 65: grade, gpa = "B",  3.0
elif pct >= 55: grade, gpa = "C+", 2.5
elif pct >= 50: grade, gpa = "C",  2.0
else:            grade, gpa = "F",  0.0

status  = "PROMOTED ✅" if all_pass else "DETAINED ❌"

# Pass/fail per subject (ternary)
pf = lambda m: "Pass" if m >= 50 else "FAIL"

# Feedback
if   pct >= 90: feedback = "🏆 Exceptional performance! Keep it up."
elif pct >= 70: feedback = "⭐ Good work. Push for the top tier."
elif pct >= 50: feedback = "📚 Passed. Focus harder on weak subjects."
else:            feedback = "⚠️  Needs improvement. Seek extra support."

# ── Print report ─────────────────────────────
print(f"""
╔══════════════════════════════════════════╗
              OFFICIAL REPORT CARD
╠══════════════════════════════════════════╣
  Student : {student}
  Roll No : {roll}
╠══════════════════════════════════════════╣
  Subject         Marks    Status
  ────────────────────────────────────────
  Mathematics   {math:>6.1f} / 100   {pf(math)}
  English       {english:>6.1f} / 100   {pf(english)}
  Science       {science:>6.1f} / 100   {pf(science)}
  Urdu          {urdu:>6.1f} / 100   {pf(urdu)}
  Computer Sc.  {cs:>6.1f} / 100   {pf(cs)}
  ────────────────────────────────────────
  Total         {total:>6.1f} / 500
  Percentage    {pct:>6.1f}%
  Grade         {grade}
  GPA           {gpa:.1f} / 4.0
  Highest Mark  {highest:.1f}     Lowest: {lowest:.1f}
╠══════════════════════════════════════════╣
  STATUS: {status}
  {feedback}
╚══════════════════════════════════════════╝""")
report_card.py — sample run
Student name : ali hassan
Mathematics : 88
English : 76
Science : 92
Urdu : 71
Computer Sc. : 95
╔══════════════════════════════════════════╗
  OFFICIAL REPORT CARD
Student : Ali Hassan    Grade : A
Total : 422.0 / 500   84.4%
STATUS : PROMOTED ✅
╚══════════════════════════════════════════╝
Notice the lambda shortcut
pf = lambda m: "Pass" if m >= 50 else "Fail" creates a small single-use function using Python's lambda keyword. You'll learn full functions in Phase 3 — this is a preview. It lets you call pf(math) instead of repeating the ternary for each subject.
🎓
Phase 1 Complete!
You've mastered all 5 Foundation lessons and built 4 real Python programs. You now have a solid command of Python's core building blocks. Phase 2 introduces the logic that makes programs truly intelligent.
Variables ✓ Data Types ✓ Strings ✓ Operators ✓ Input/Output ✓ f-Strings ✓ Type Conversion ✓ 4 Real Programs ✓
Course Home
Phase 1 Complete4 projects built