[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
# define functions for addition, subtraction, multiplication, and division def add(num1, num2): return num1 + num2 def subtract(num1, num2): return num1 - num2 def multiply(num1, num2): return num1 * num2 def divide(num1, num2): return num1 / num2 # take user input for operation choice and two numbers operation = input("Enter an operation (+, -, *, /): ") num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) # perform the selected operation if operation == '+': result = add(num1, num2) elif operation == '-': result = subtract(num1, num2) elif operation == '*': result = multiply(num1, num2) elif operation == '/': result = divide(num1, num2) else: print("Invalid operation") # output the result print("Result: ", result)
[/dm_code_snippet]