โš™๏ธ Function Builder

Python-Powered Calculator - Day 4 Demo

๐Ÿ”ง Function Builder

๐Ÿงฎ Live Calculator

Ready to calculate!

๐Ÿ’ก Function Examples

Basic Calculator
def calculate(a, op, b): if op == '+': return a + b if op == '-': return a - b if op == '*': return a * b if op == '/': return a / b
Simple arithmetic operations
Advanced Calculator
def advanced_calc(a, op, b): operations = { '+': lambda x, y: x + y, '-': lambda x, y: x - y, '*': lambda x, y: x * y, '/': lambda x, y: x / y if y != 0 else 'Error' } return operations.get(op, 'Invalid op')(a, b)
Uses dictionary for cleaner code
Scientific Calculator
def scientific_calc(x, operation): import math ops = { 'sqrt': math.sqrt, 'square': lambda n: n ** 2, 'log': math.log10 } return ops.get(operation, 'Invalid')(x)
Mathematical operations

๐Ÿ Python Concepts in Action

This demo shows how functions make your code reusable and organized:

# Python function power - this is what makes the calculator work! def calculate(num1, operation, num2): """Perform calculation based on operation""" if operation == '+': return num1 + num2 elif operation == '-': return num1 - num2 elif operation == '*': return num1 * num2 elif operation == '/': if num2 != 0: return num1 / num2 else: return "Cannot divide by zero!" # Using the function result = calculate(10, '+', 5) print(result) # Output: 15

๐ŸŽฏ Key Function Concepts: