-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_demo.py
More file actions
67 lines (55 loc) · 1.12 KB
/
gen_demo.py
File metadata and controls
67 lines (55 loc) · 1.12 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
# generators / yield
def station():
yield "HUA"
yield "SAM"
yield "SIL"
yield "LUM"
def sum_all_digit(n):
return sum([int(c) for c in str(n)])
def lucky(target=9, start_num=1, stop_num=100):
d = []
for i in range(start_num, stop_num + 1):
if sum_all_digit(i) == target:
d.append(i)
return d
def luck_gen(target=9, start_num=1):
i = start_num
while True:
if sum_all_digit(i) == target:
yield i
i += 1
def zip_demo():
pretest = [5, 7, 4, 8, 10]
posttest = [6, 7, 5, 10, 9]
z = zip(pretest, posttest)
print(next(z))
print("-" * 80)
for i, j in z:
print(i, j)
print("-" * 80)
print(next(z))
zip_demo()
# print(lucky(8, 1, 100))
# g = luck_gen(8, 1000)
# print(g)
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# s = station()
# print(s)
# print(next(s))
# print(next(s))
# print(next(s))
# print(next(s))
# print(next(s))