70.1k views
1 vote
How do I put this in python for my class

How do I put this in python for my class-example-1

1 Answer

3 votes

Answer:

def perform_operation(operation, value1, value2):

if operation == "+":

return value1 + value2

elif operation == "-":

return value1 - value2

elif operation == "*":

return value1 * value2

elif operation == "/":

return value1 / value2

else:

return "Invalid operation"

print(perform_operation("+", 4, 10))

Step-by-step explanation:

In this case, the function will return the result of adding 4 and 10, which is 14. You can then use the result variable to access the returned value.

Note that you can also use this function to perform other operations, such as subtraction or multiplication. For example, you can call the function like this to subtract two values:

print(perform_operation("-", 4, 10))

In this case, the function will return the result of subtracting 10 from 4, which is -6.

User Johann Combrink
by
6.2k points