-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevolution.py
More file actions
70 lines (58 loc) · 1.83 KB
/
revolution.py
File metadata and controls
70 lines (58 loc) · 1.83 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
#!/usr/bin/env python3
# Chris's code for calculating volume of a shape revolving around an axis.
def squarePoly(coList):
prod = []
for i in range(2 * len(coList) - 1):
prod.append(0)
for i in range(len(coList)):
for j in range(len(coList)):
prod[i + j] += coList[i] * coList[j]
return prod
def intPoly(coList):
intList = [0]
for i in range(len(coList)):
intList.append(coList[i] / (i + 1))
return intList
def defIntRange(x1, x2, coList):
total = 0
for i in range(len(coList)):
total += ((x2) ** i - (x1) ** i) * coList[i]
return total
def printList(ls):
for item in ls:
print(item, end=' ')
print()
def doEverything(coeff, highBound, lowBound, markVolume):
volume = defIntRange(lowBound, highBound, intPoly(squarePoly(coeff))) * 3.14159
print(round(volume, 2))
height = lowBound
iterVolume = 0.0
nextMark = markVolume
marks = []
if volume > markVolume:
while height < highBound:
iterVolume = defIntRange(lowBound, height, intPoly(squarePoly(coeff))) * 3.14159
if iterVolume > nextMark:
if len(marks) < 8:
nextMark += markVolume
marks.append(round(height - lowBound, 2))
else:
break
height += .001
printList(marks)
else:
print("insufficient volume")
case = 1
while True:
try:
length = input()
polynomial = list(map(float, input().split(" ")))
low, high, iterVolume = input().split(" ")
low = float(low)
high = float(high)
iterVolume = float(iterVolume)
print("Case", case, end=': ')
case += 1
doEverything(polynomial, high, low, iterVolume)
except EOFError:
break