-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfp.py
More file actions
72 lines (52 loc) · 1.4 KB
/
fp.py
File metadata and controls
72 lines (52 loc) · 1.4 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
71
72
# arr = [1,2,3,4,5]
# arr = range(5)
# def my_sum(numbers):
# total = 0
# for i in numbers:
# total = total + i
# return total
# print my_sum(arr)
# def my_product(numbers):
# total = 1
# for i in numbers:
# total = total * i
# return total
# return totaltotal
# print my_product(arr)
# def my_reduce(numbers, fn, initial):
# total = initial
# for i in numbers:
# total = fn(total, i)
# return total
# print my_reduce(arr, lambda t,x: t+x, 0)
# print my_reduce(arr, lambda t,x: t*x, 1)
# print all([True, True, True])
# print any([False, False, True])
# print sum(arr)
# print max(arr)
# print min(arr)
# # map fn with iterator
# print map(lambda x: x+10, arr)
# # filter list out of iterator
# print filter(lambda x: x%2==0, arr)
# print arr
# lst = range(10, 20)
# lst1 = range(5,15)
# # zip combine multiple lists to 1
# print zip(arr, lst, lst1)
# # sorted a list by key
# print sorted([74,56,23,105], key=lambda x:x)
# def f(a):
# print a
# print reduce(lambda _,x: f(x), range(5), 0)
# 3辆车比赛, 分别给3辆车70%的概率往前走一步,一共有5次机会,我们打出每次这3辆车的前行状态
from random import random
times=5
positions=[1,1,1]
while times > 0:
times -= 1
print ''
for i in range(len(positions)):
if random() > 0.3:
positions[i] += 1
print '-' * positions[i]