-
Notifications
You must be signed in to change notification settings - Fork 0
/
task1.py
74 lines (71 loc) · 2 KB
/
task1.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
def sums(list):
#list = input()
sums = [0]
currentSum = 0
for item in list:
currentSum+=item
sums.append(currentSum)
print sums
def bounds(list,lowerBound,upperBound):
newList = []
if (lowerBound > upperBound):
print "incorrect bounds"
for item in list:
if (item < lowerBound):
newList.append(lowerBound)
elif (item > upperBound):
newList.append(upperBound)
else:
newList.append(item)
print newList
def sequence(n):
print n
while n != 1:
if n%2==0:
n /= 2
else:
n = 3*n+1
print n
def bottles():
numbers = ["no","one","two","three","four","five","six","seven","eight","nine","ten"]
numberOfBottles = 10
bottle = " green bottle"
hanging = " hanging on the wall"
bottles = " green bottles"
ifStr = "And if one green bottle should accidentally fall,"
willBe = "There'll be "
while (numberOfBottles > 0):
numberStr = numbers[numberOfBottles].title()
if (numberOfBottles != 1):
print numberStr + bottles + hanging + ","
print numberStr + bottles + hanging + ","
else:
print numberStr + bottle + hanging + ","
print numberStr + bottle + hanging + ","
print ifStr
if (numberOfBottles != 2):
print willBe + numbers[numberOfBottles-1] + bottles + hanging + "."
else:
print willBe + numbers[numberOfBottles-1] + bottles + hanging + "."
numberOfBottles-=1
bottles()
def getPair(n,divisor):
count = 0
while n%divisor == 0:
n/=divisor
count+=1
return [divisor,count]
def primes(n):
divisor = 2
divisors = []
while divisor < n :
if n%divisor == 0:
[divisor,count]=getPair(n,divisor);
divisors.append([divisor,count])
n/= divisor**count
divisor+=1
print divisors
primes(144)
#sequence(3)
#sums()
#bounds([1,2,3,4,5,9],2,4)