-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_optimized.py
37 lines (32 loc) · 1.01 KB
/
calc_optimized.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
import math
print("""
1. Addition
2. Substraction
3. Multiplication
4. Devision
5. Power
6. Square Root
Enter what type of calculation would you like to do: """)
type_of_calculation = int(input().strip())
if type_of_calculation not in [1, 2, 3, 4, 5, 6]:
print("You need to select from numbers between 1 and 6")
exit()
num_1 = float(input("Enter the first number: "))
if type_of_calculation == 6:
num_2 = None
else:
num_2 = float(input("Enter the second number: "))
if type_of_calculation == 1:
result = num_1 + num_2
elif type_of_calculation == 2:
result = num_1 - num_2
elif type_of_calculation == 3:
result = num_1 * num_2
elif type_of_calculation == 4:
result = num_1 / num_2
elif type_of_calculation == 5:
result = num_1 ** num_2
else:
result = math.sqrt(num_1)
calculation_types = ["addition", "subtraction", "multiplication", "division", "power", "square root"]
print(f"Result of your {calculation_types[type_of_calculation-1]} is: {result}")