get operator as input in python 1

get operator as input in python

def operation(number1, number2, operator):
    if operator == '+':
        return number1 + number2
    elif operator == '-':
        return number1 - number2

Here is what the above code is Doing:
1. It’s defining a function called operation.
2. It’s taking in three parameters: number1, number2, and operator.
3. It’s checking to see if the operator is a plus sign. If it is, it returns the sum of number1 and number2.
4. If the operator is not a plus sign, it checks to see if the operator is a minus sign. If it is, it returns the difference of number1 and number2.
5. If the operator is neither a plus sign nor a minus sign, it returns nothing.

Similar Posts