forked from david-gary/CalculatorLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscientificOperations.py
More file actions
40 lines (31 loc) · 1.04 KB
/
scientificOperations.py
File metadata and controls
40 lines (31 loc) · 1.04 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
36
37
38
39
40
import math
def scientific_calculate(operation, num1):
"""
Performs the given scientific operation on the given number, which may be either an integer or a float.
args:
- operation: the operation to perform (sin, cos, tan, ln)
- num1: the number to perform the operation on
returns:
- the result of the operation on the given number
"""
if operation == 'sin':
return math.sin(num1)
elif operation == 'cos':
# Calculate the cosine
cosine = math.cos(num1)
# Return the cosine
return cosine
elif operation == 'tan':
# Calculate the tangent
tangent = math.tan(num1)
# Return the tangent
return tangent
elif operation == 'ln':
# Calculate the natural log
natLog = math.log(num1)
# Return the natural log of num1
natlog = math.log(num1)
return natlog
else:
raise ValueError(
'Invalid Operation: Scientific Operations are (sin, cos, tan, ln, sqrt, !, ^, and %)')