数列计算函数
因为第二个数n是两个数的和,所以减去n???好吧,我也没太搞明白
import sys
m = input()
n = input()
if '.' in m or '.' in n:
print("illegal input")
sys.exit(0)
ans = [int(m),int(n)]
for i in range(20):
ans.append(ans[-1]+ans[-2])
print(ans[21]-int(n))
字母计数
s = input()
sorted(s)
ans = {}
j = 0
i = 1
for i in range(1, len(s), 1):
if s[j] != s[i]:
ans[s[j]] = i - j
j = i
ans[s[j]] = len(s) - j
res = ["hello cqupt"]
times = 0
for key, values in ans.items():
if times < values:
res.clear()
res.append(key)
times = values
elif times == values:
res.append(key)
for k in res:
print(k, ans[k])
文件中数据转列表2
f = open('xrdfile.txt', 'r+',encoding='utf-8')
ans = []
k = f.readlines()
f.close()
for i in k:
if i =='\n':
continue
i = i.strip('\n')
if '。' in i:
continue
i = i.split()
j = list(map(eval,i))
j = list(map(int, j))
ans.append(j)
le = eval(input())
ans = ans[0:le]
print(ans)