Calculator

def calculator():
    print("Welcome to the Basic Calculator!")
    print("Options: add, subtract, multiply, divide")
    
    # Get user inputs
    operation = input("Enter the operation: ").strip().lower()
    a = float(input("Enter the first number: "))
    b = float(input("Enter the second number: "))
    
    # Perform the calculation
    if operation == "add":
        result = a + b
    elif operation == "subtract":
        result = a - b
    elif operation == "multiply":
        result = a * b
    elif operation == "divide":
        if b == 0:
            return "Error: Division by zero"
        result = a / b
    else:
        return "Invalid operation"
    
    return f"The result is: {result}"

# Run the calculator
print(calculator())

Comments

Popular posts from this blog

Tamil Nadu Man Crashes His New Car Into Temple Pillar Minutes After 'Puja'

Big Security Breach As Virat Kohli Is Stunned By Fan Who Hoodwinked All

JEE Main Session 2 Exam City Slip 2024 likely today, check important details here