-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_code.py
More file actions
63 lines (51 loc) · 1.11 KB
/
Copy pathbase_code.py
File metadata and controls
63 lines (51 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
57
58
59
60
61
# 求杨辉三角第n行第k列
# m 行有m个元素,所以k不能大于m
# 1
# 11
# 121
# 1331
m = 5
k = 4
triangle = []
for i in range(m):
# 所有行都需要1开头
row = [1]
triangle.append(row)
if i == 0 :
continue
for j in range(1, i):
row.append(triangle[i-1][j-1]+triangle[i-1][j])
row.append(1)
# print(triangle)
# R-1.1
def is_multiple(n, m):
try:
if n == int(n) and m == int(m):
a, b = divmod(n, m)
return True if a >0 and b == 0 else False
else:
print('zhe parameter must be int type')
except (TypeError, ValueError):
print('zhe parameter must be int type')
return 'Error'
# print(is_multiple('a', 'b'))
# print(is_multiple(1,1.5))
# R-1.3
# def minmax(lst):
# mixnumber = 0
# maxnumber = 0
# for i in lst:
# if
# R-1.4
def sumsquare(n):
ret = 0
for i in range(1, n+1):
ret += i**2
return ret
# print(sumsquare(3))
# R-1.5
def sumsquare(n):
ret = [x*x for x in range(1, n+1)]
return sum(ret)
# print(sumsquare(3))
# R-1.12