-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3D_calculator.py
More file actions
151 lines (125 loc) · 4.08 KB
/
3D_calculator.py
File metadata and controls
151 lines (125 loc) · 4.08 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
pi = 3.1415926535897931
def cube():
while True:
try:
my1 = int(input("Enter the cube edge value: "))
V = my1 * my1 * my1
except:
print("Error. Please enter numeric value only ->")
continue
else:
print(f"The volume of your cube is {V}! Thank you!")
break
def sphere():
while True:
try:
my1 = int(input("Enter the sphere radius value: "))
V = 4.0 / 3.0 * pi * my1**3
except:
print("Error. Please enter numeric value only ->")
continue
else:
print(f"The volume of your sphere is {V}! Thank you!")
break
def cuboid():
while True:
try:
my1 = int(input("Enter the cuboid lenght value: "))
my2 = int(input("Enter the cuboid width value: "))
my3 = int(input("Enter the cuboid height value: "))
V = my1 * my2 * my3
except:
print("Error. Please enter numeric value only ->")
continue
else:
print(f"The volume of your cuboid is: {V}! Thank you!")
break
def cone():
while True:
try:
my1 = int(input("Enter the cone radius value: "))
my2 = int(input("Enter the cone height value: "))
V = pi * (my1 * my1) * my2 / 3
except:
print("Error. Please enter numeric value only.")
continue
else:
print(f"The volume of your cone is {V}! Thank you!")
break
def cylinder():
while True:
try:
my1 = int(input("Enter the cylinder radius value: "))
my2 = int(input("Enter the cylinder height value: "))
V = pi * (my1 * my1) * my2
except:
print("Error. Please enter numeric value only")
continue
else:
print(f"The volume of your cylinder is {V}! Thank you!")
break
def prism():
while True:
try:
my1 = int(input("Enter the prism base surface value: "))
my2 = int(input("Enter the prism height value : "))
V = my1 * my2
except:
print("Error. Please enter numeric value only")
continue
else:
print(f"The volume of your prism is {V}! Thank you!")
break
def pyramid():
while True:
try:
my1 = int(input("Enter the pyramind base length value: "))
my2 = int(input("Enter the pyramid base width value: "))
my3 = int(input("Enter the pyramid height value: "))
V = (my1 * my2 * my3) / 3
except:
print("Error. Please enter numeric value only.")
continue
else:
print(f"The volume of your pyramid is {V}! Thank you!")
break
def use_again():
question = input("Would you like to choose another object (yes/no)?: ")
if question.lower() == "yes":
calculator()
if question.lower() == "no":
print("Thank you for using 3D object volume calculator!")
quit()
else:
print("Error. Please answer with 'yes' or 'no' ->")
use_again()
def calculator():
print(
"Welcome to the 3D object volume calculator. You can choose any of the given objects from the list: * Cube; * Sphere; * Cuboid; * Cone; * Cylinder; * Prism; * Pyramid."
)
choice = input("Choose your 3D object. Simply type the name of the object: ")
if choice.lower() == "cube":
cube()
use_again()
if choice.lower() == "sphere":
sphere()
use_again()
if choice.lower() == "cuboid":
cuboid()
use_again()
if choice.lower() == "cone":
cone()
use_again()
if choice.lower() == "cylinder":
cylinder()
use_again()
if choice.lower() == "prism":
prism()
use_again()
if choice.lower() == "pyramid":
pyramid()
use_again()
else:
print("Error. Please type the name of the object correctly and start from the start")
calculator()
calculator()