0
点赞
收藏
分享

微信扫一扫

【Python Practice】Day 16 Question 60-64(递归)


'''
@Author: your name
@Date: 2020-07-22 16:34:10
@LastEditTime: 2020-07-22 17:33:54
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day16.py
'''
# Question 60
# 使用迭代计算
def Q60(n):
if n>0:
return Q60(n-1)+100
else:
return 0

# Question 61
# The Fibonacci Sequence is computed based on the following formula:
def Q61(n):
if n==0:
return 0
elif n==1:
return 1
else:
return Q61(n-1)+Q61(n-2)

# Question 62
# 在61的基础上,输出之前的数对应的函数值
def Q62(n):
r=[str(Q61(i)) for i in range(n+1)]
print(",".join(r))

# Question 63
# 输出偶数
def Q63(n):
l=[]
for i in range(0,n+1):
if i%2==0:
l.append(str(i))
print(",".join(l))



# Question 64
# 输出能被5和7整除的数
def Q64(n):
l=[]
for i in range(0,n+1):
if i%5==0 and i%7==0:
l.append(str(i))
print(",".join(l))

if __name__ == "__main__":

n=int(input())
# print(Q60(n))

# print(Q61(n))

# Q62(n)

# Q63(n)

Q64(n)


举报

相关推荐

0 条评论