Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!usr/local/bin/python3.8
- # -*- coding: utf-8 -*import
- OPERATORS = ('+', '-', '*', '/')
- def plus(*args):
- return sum(args)
- def minus(*args):
- args = list(args)
- result = 0
- for x in args:
- result -= x
- return result
- def multiply(*args):
- args = list(args)
- result = 1
- for i in args:
- result *= i
- return result
- def div(*args):
- args = list(args)
- if 0 not in args:
- result = 1
- for i in args:
- result /= i
- return result
- else:
- return 0
- operations = {
- '+': plus,
- '-': minus,
- '*': multiply,
- '/': div,
- }
- def operate(*args):
- operator = args[0]
- args = args[1:]
- if operator in OPERATORS:
- if args:
- result = operations[operator](*args)
- return result
- else:
- return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement