Advertisement
valeri1383

Untitled

Dec 4th, 2020
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. def operate(operator, *args):
  2.     operator = operator
  3.     counter = 0
  4.     result = 0
  5.  
  6.     if operator == '+':
  7.         for i in args:
  8.             result += i
  9.         return result
  10.  
  11.     elif operator == '-':
  12.         for i in args:
  13.             if counter == 0:
  14.                 result = i
  15.                 counter += 1
  16.                 continue
  17.             result -= i
  18.         return result
  19.  
  20.     elif operator == '*':
  21.         result = 1
  22.         for i in args:
  23.             result *= i
  24.         return result
  25.  
  26.     elif operator == '/':
  27.         for i in args:
  28.             if counter == 0:
  29.                 result = i
  30.                 counter += 1
  31.                 continue
  32.             result /= i
  33.         return result
  34.  
  35. print(operate("/", 10, 5))
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement