-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfun.py
More file actions
53 lines (39 loc) · 716 Bytes
/
fun.py
File metadata and controls
53 lines (39 loc) · 716 Bytes
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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
def fact(n):
if n == 1:
return 1
return n * fact(n - 1)
print(fact(3))
def cal_sum(*args):
sumx=0
for n in args:
sumx += n
return sumx
print(cal_sum(1,2,3,4,5))
def lazy_sum(*args):
def sumx():
ax=0
for n in args:
ax += n
return ax
return sumx
f1=lazy_sum(1,3,5,7,9)
f2=lazy_sum(1,3,5,7,9)
print f1==f2
print f1()==f2()
def count():
fs = []
for i in range(1, 4):
def f(i):
return i*i
fs.append(f(i))
return fs
f1, f2, f3=count()
print f1,f2,f3
f=lambda x:x*x
print f(2)
def build(x,y):
return lambda :x*x+y*y
f=build(3,4)
print f()