Untitled

 avatar
unknown
plain_text
2 years ago
911 B
5
Indexable
# 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)
Editor is loading...