-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest21.py
More file actions
56 lines (53 loc) · 1.11 KB
/
test21.py
File metadata and controls
56 lines (53 loc) · 1.11 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
# -*- coding: utf-8 -*-
a = [x for x in xrange(1,100,2)]
def trim(s):
#sl = list(s)
if len(s) != 0:
if s[0] == ' ':
return trim(s[1:])
if s[-1] == ' ':
return trim(s[:-1])
#s = ''.join(sl)
return s
# -*- coding: utf-8 -*-
def findMinAndMax(L):
if L != []:
min = L[0]
max = L[0]
for x in L:
if x < min:
min = x
if x > max:
max = x
return (min, max)
return (None, None)
def triangles():
l = [1]
yield l
while True:
l = [1] + [l[x] + l[x+1] for x in range(len(l)-1)] + [1]
yield l
n = 0
results = []
for t in triangles():
print(t)
results.append(t)
assert n != 0 ,'n is zero'
n = n + 1
if n == 10:
break
if results == [
[1],
[1, 1],
[1, 2, 1],
[1, 3, 3, 1],
[1, 4, 6, 4, 1],
[1, 5, 10, 10, 5, 1],
[1, 6, 15, 20, 15, 6, 1],
[1, 7, 21, 35, 35, 21, 7, 1],
[1, 8, 28, 56, 70, 56, 28, 8, 1],
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
]:
print('测试通过!')
else:
print('测试失败!')