PrashanthB461 commited on
Commit
bda2e64
·
verified ·
1 Parent(s): bcd9a1f

Create calculator/operations.py

Browse files
Files changed (1) hide show
  1. calculator/operations.py +20 -0
calculator/operations.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def perform_calculation(numbers, operation):
2
+ if operation == "add":
3
+ return sum(numbers)
4
+ elif operation == "subtract":
5
+ return numbers[0] - sum(numbers[1:])
6
+ elif operation == "multiply":
7
+ result = 1
8
+ for num in numbers:
9
+ result *= num
10
+ return result
11
+ elif operation == "divide":
12
+ try:
13
+ result = numbers[0]
14
+ for num in numbers[1:]:
15
+ result /= num
16
+ return result
17
+ except ZeroDivisionError:
18
+ return "Error: Division by zero!"
19
+ else:
20
+ return "Unsupported operation!"