-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscientificcalculator.py
46 lines (45 loc) · 1.42 KB
/
scientificcalculator.py
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
41
42
43
44
45
46
'''You task is to build a scientific calculator that performs all the below listed functionalities.'''
# Importing the required modules
import math
import sys
# Defining the main function
def main():
'''This is the main function'''
# Getting the user input
number = input('Enter the number: ')
option = input('Enter the option: ')
# Calling the function to get the result
result = scientific_calculator(number, option)
# Printing the result
print(result)
# Defining the function to perform the scientific calculations
def scientific_calculator(number, option):
'''This function performs the scientific calculations'''
# Converting the number to float
number = float(number)
# Performing the calculations
if option == 'sin':
result = math.sin(number)
elif option == 'cos':
result = math.cos(number)
elif option == 'tan':
result = math.tan(number)
elif option == 'log':
result = math.log(number)
elif option == 'log10':
result = math.log10(number)
elif option == 'sqrt':
result = math.sqrt(number)
elif option == 'ceil':
result = math.ceil(number)
elif option == 'floor':
result = math.floor(number)
elif option == 'exp':
result = math.exp(number)
else:
result = 'Invalid option'
# Returning the result
return result
# Calling the main function
if __name__ == '__main__':
main()