Advertisement
viligen

operate

Jan 26th, 2022
719
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from functools import reduce
  2.  
  3.  
  4. def operate(operator, *args):
  5.     if operator == '+':
  6.         return reduce(lambda x, y: x + y, args)
  7.     elif operator == '-':
  8.         return reduce(lambda x, y: x - y, args)
  9.     elif operator == '*':
  10.         return reduce(lambda x, y: x * y, args)
  11.     elif operator == '/' and 0 not in args:
  12.         return reduce(lambda x, y: x / y, args)
  13.  
  14.  
  15. print(operate("+", 1, 2, 3))
  16.  
  17.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement