Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import reduce
- def operate(operator, *args):
- if operator == '+':
- return reduce(lambda x, y: x + y, args)
- elif operator == '-':
- return reduce(lambda x, y: x - y, args)
- elif operator == '*':
- return reduce(lambda x, y: x * y, args)
- elif operator == '/' and 0 not in args:
- return reduce(lambda x, y: x / y, args)
- print(operate("+", 1, 2, 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement