跳到主要内容

Python 错题集

第一个只能检测有这个 key 的情况,而第三个就算没有这个 key 也能运行。

import os

def locate_universe_formula():
for root, dirs, files in os.walk(r'/tmp/documents'):
for name in files:
if (name == 'universe-formula'):
return os.path.abspath(os.path.join(root, name))

def get_value_from_pytramid(l, c):
ret = []

for i in range(l+2):
if i == 0:
ret.append([1])
elif i == 1:
ret.append([1, 1])
else:
col = []
for j in range(i+1):
if j == 0 or j == i:
col.append(1)
else:
col.append(ret[i-1][j-1] + ret[i-1][j])
ret.append(col)
return ret[l][c]


# result = get_value_from_pytramid(4, 2) # result -> 6
# result = get_value_from_pytramid(5, 0) # result -> 1
result = get_value_from_pytramid(67, 34)
print(result)