-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheverything.py
193 lines (149 loc) · 4.64 KB
/
everything.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env python3
#This is a backup file with all the code of the programme
class Triangle:
def __init__(self,base,height,area):
self.base=base
self.height=height
self.area=area
def area(self):
return self.area
class Rectangle:
def __init__(self,width,height,area):
self.width=width
self.height=height
self.area=area
def area(self):
return self.area
class Circle:
def __init__(self,radius,area):
self.width=radius
self.area=area
def area(self):
return self.area
#Lists where all info about the shapes are saved
triangles =[]
rectangles =[]
circles =[]
#List where only the area of the shapes are saved
triA =[]
recA =[]
circA=[]
def shapes():
import math
while True:
choose = input("Choose a shape (triangle- t, rectangle - r, circle - c) . q quits:")
if choose == "q":
break;
if choose in ['triangle','TRIANGLE','Triangle','t','T']:
base = input("Give base of the triangle:")
height = input("Give height of the triangle:")
area =0.5*float(base)*float(height)
tri= Triangle(base,height,area)
triangles.append(tri)
print("The area is","%.2f" %area)
elif choose in ['rectangle','RECTANGLE','Rectangle','r','R']:
width = input("Give width of the rectangle:")
height = input("Give height of the rectangle:")
area =float(width)*float(height)
rec= Rectangle(width,height,area)
rectangles.append(rec)
print("The area is","%.2f" %area)
elif choose in ['circle','CIRCLE','Circle','c','C']:
radius = input("Give radius of the circle:")
area =(float(radius)**2)*3.14159265358979323846
circ= Circle(radius,area)
circles.append(circ)
print("The area is","%.2f" %area)
else:
print("Unknown shape! Try again!")
def funny():
import random
print("\nFunny shape fact: \n")
Funnyinfo =[
"The first theorems relating to circles are attributed to Thales around 650 BC",
"A triangle is the sign for God, Jesus and The Holy Spirit in christianity",
"A rectangle is the most common shape for a rug",
"Infants prefere circles to other shapes"]
print(random.choice(Funnyinfo))
reply =input("Interesting, right?")
if input== "ok":
ui()
else:
ui()
def stat():
import re
import numpy as np
import matplotlib.pyplot as plt
print("\nAmount of calculations you have made so far:")
print("\tTriangles: ",len(triangles))
print("\tRectangles: ",len(rectangles))
print("\tCircles: ",len(circles))
print("\nAreas of your triangles:")
for i in triangles:
print("\t","%.2f" %i.area)
ta= int(i.area)
triA.append(ta)
if len(triA) >1:
t=plt.plot(triA,'mo')
plt.title("Triangle areas")
plt.ylabel("area")
plt.xlabel("triangles")
plt.xticks(range(0, len(triA)))
plt.show(t)
print("\nAreas of your rectangles:")
for i in rectangles:
print("\t","%.2f" %i.area)
ra = int(i.area)
recA.append(ra)
if len(recA)>1:
r=plt.plot(recA,'ro')
plt.title("Rectangle areas")
plt.ylabel("area")
plt.xlabel("rectangles")
plt.xticks(range(0, len(recA)))
plt.show(r)
print("\nAreas of your circles:")
for i in circles:
print("\t","%.2f" %i.area)
ca = int(i.area)
circA.append(ca)
if len(circA)>1:
c=plt.plot(circA,'ko')
plt.title("Circle areas")
plt.ylabel("area")
plt.xlabel("circles")
plt.xticks(range(0, len(circA)))
plt.show(c)
ready=input("Press any key to go back to the main menu")
if re.match(r"[Oo][Kk]", ready):
ui()
else:
ui()
def ui():
goOn = True
while goOn:
ask=input("""\n***** This is a programme for calculating areas of shapes *****\n
What do you want to do? \n
Press...\n
c to -> Calculates areas for shapes\n
s for -> Statistics\n
f for -> Funny shape info\n
q to quit """)
if ask =="q":
sure = input("Are you sure you want to quit? y/n")
if sure == "y":
goOn = False
else:
continue
elif ask =="c":
shapes()
elif ask =="s":
stat()
elif ask =="f":
funny()
else:
print("Unknown input")
continue
def main():
ui()
main()