🧮 Day 7: Build a Calculator

Your Final Python Project!

🎉

Congratulations!

You've made it to the final day! Today you'll build a complete calculator using everything you've learned.

📋 Project Overview

Your calculator should:

💻 The Calculator Code

def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def divide(a, b): if b == 0: return "Error: Cannot divide by zero!" return a / b def calculator(): print("🧮 Simple Calculator") print("Operations: +, -, *, /") print("Type 'quit' to exit\n") while True: operation = input("Operation: ") if operation == "quit": print("Goodbye! 👋") break try: num1 = float(input("First number: ")) num2 = float(input("Second number: ")) except ValueError: print("❌ Please enter valid numbers!\n") continue if operation == "+": print(f"Result: {add(num1, num2)}\n") elif operation == "-": print(f"Result: {subtract(num1, num2)}\n") elif operation == "*": print(f"Result: {multiply(num1, num2)}\n") elif operation == "/": print(f"Result: {divide(num1, num2)}\n") else: print("❌ Invalid operation! Use +, -, *, or /\n") # Run the calculator calculator()

📖 How It Works

  1. Functions - We created separate functions for each operation
  2. While Loop - Keeps the calculator running until user quits
  3. Try/Except - Handles invalid number inputs gracefully
  4. If/Elif/Else - Chooses which operation to perform
  5. F-strings - Formats the output nicely
💡 Try This: Add more operations like power (**), modulo (%), or floor division (//). Can you add a history feature that remembers past calculations?

🚀 Challenge Extensions

Want to make it even better? Try these:

🐍

You Did It!

You've completed all 7 days of One Week Python!

What You Learned:

Day 1: print() Day 2: Variables Day 3: If/Else Day 4: Functions Day 5: Lists Day 6: Files Day 7: Project!

This is just the beginning. Keep coding, keep building, and most importantly - have fun! 🎉

You've reached 100%!