每日一题 2019.9.23
作者:互联网
# coding=utf-8
"""
有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和.
"""
fenZi1 = 2
fenZi2 = 3
fenZi = []
fenMu1 = 1
fenMu2 = 2
fenMu = []
fenZi.append(fenZi1)
fenZi.append(fenZi2)
fenMu.append(fenMu1)
fenMu.append(fenMu2)
def getFenZi(n, num1, num2):
if n + 2 < 20:
n += 1
num1, num2 = num2, num1 + num2
fenZi.append(num2)
getFenZi(n, num1, num2)
else:
print("fenzi ok !")
def getFenMu(n, num1, num2):
if n + 2 < 20:
n += 1
num1, num2 = num2, num1 + num2
fenMu.append(num2)
# print(num2)
getFenMu(n, num1, num2)
else:
print("fenmu ok")
def sumNum(num1, num2):
num = []
sum = 0
for i in range(20):
num.append(num1[i]/num2[i])
print(num)
for j in range(20):
sum += num[j]
return sum
if __name__ == '__main__':
getFenZi(0, fenZi1, fenZi2)
getFenMu(0, fenMu1, fenMu2)
print(fenZi)
print(fenMu)
sum = sumNum(fenZi,fenMu)
print(sum)
# 写太麻烦了 主要目的是想练习一下函数
# 初学Python 如有不足 请多多指教
标签:20,num1,num2,23,每日,fenMu,print,append,2019.9 来源: https://www.cnblogs.com/walxt/p/11574761.html