forked from david-gary/CalculatorLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleOperations.py
More file actions
35 lines (30 loc) · 1.11 KB
/
simpleOperations.py
File metadata and controls
35 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def simple_calculate(operation, num1, num2):
"""
Performs the given simple operation on the given numbers, which may be either integers or floats.
args:
- operation: the operation to perform (+, -, *, or /)
- num1: the first number
- num2: the second number
returns:
- the result of the operation on the given numbers
"""
if operation == '+':
return num1 + num2
elif operation == '-':
# TODO: finish this statement
# - should return the result of subtracting num2 from num1
return num1 - num2
elif operation == '*':
# TODO: finish this statement
# - should return the result of multiplying num1 by num2
return num1 * num2
elif operation == '/':
# TODO: finish this statement
# - should return the result of dividing num1 by num2
# - remember to raise a ValueError if num2 is 0
return num1 / num2
elif num2 == 0:
raise ValueError ("Cannot divide by 0")
else:
raise ValueError(
'Invalid Operation: Simple Operations are (+, -, *, and /)')