You've learned the foundations. Now apply everything — variables, strings, operators, input, and output — to build 4 actual programs from scratch.
# ══════════════════════════════════════════════ # 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)
quit. You'll learn loops in Phase 2 — try to add this after Lesson 8.# ══════════════════════════════════════════════ # 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}")
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.# ══════════════════════════════════════════════ # 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}""")
# ══════════════════════════════════════════════ # 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} ╚══════════════════════════════════════════╝""")
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.