Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
911 B
1
Indexable
Never
# This is a simple calculator program.
# Define the functions for addition, subtraction, multiplication, and division.
def add(x, y):
    return x + y
def subtract(x, y):
    return x - y
def multiply(x, y):
    return x * y
def divide(x, y):
    return x / y
# Get the user's input for the two numbers and the operation to perform.
first_number = int(input("Enter the first number: "))
second_number = int(input("Enter the second number: "))
operation = input("Enter the operation to perform (+, -, *, /): ")
# Perform the operation and print the result.
if operation == "+":
    result = add(first_number, second_number)
elif operation == "-":
    result = subtract(first_number, second_number)
elif operation == "*":
    result = multiply(first_number, second_number)
elif operation == "/":
    result = divide(first_number, second_number)
else:
    print("Invalid operation.")
print("The result is", result)