Define a function math(num1, num2, operation) that takes three arguments and it should perform math operations ( +,-,* and /) on two numbers num1 and num2 based on the operation symbol, and then it should return the result. The main part of the program should prompt users to provide num1, num2, and an operation symbol separately and then call the function with user inputs and display the result back to the user.
Function definition should look like this in your module file:
def math(num1 ,num2, operation):
#function statements
def math(num1, num2, operation): if operation == '+': return num1 + num2 elif operation == '-': return num1 - num2 elif operation == '*': return num1 * num2 elif operation == '/': return num1 / num2 else: return "Invalid operation" def main(): num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) operation = input("Enter operator: ") print("Result:", math(num1, num2, operation)) main()
Get Answers For Free
Most questions answered within 1 hours.