当前位置:网站首页>实例028:递归求等差数列
实例028:递归求等差数列
2022-08-02 06:16:00 【懒笑翻】
题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?
解题:
"""
学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群,可扫文末的推广进群哦
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
"""
def age(n):
if n == 1:
return 10 # 如果是第一个人那么就是10岁
return 2 + age(n - 1) # 第n个人就加(n-1)次2
print(age(5)) # 18结果:

边栏推荐
猜你喜欢

Vscode连接远程服务器出现‘Acquiring lock on/home/~’问题

MySQL Advanced Statements (1)

速看!PMP新考纲、PMBOK第七版解读

Nodejs installation tutorial

实验7 MPLS实验
![(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints](/img/e0/385579fc8657db8b175318bd739908.gif)
(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints

数据库概论之MySQL表的增删改查2

Nodejs installation and global configuration (super detailed)

HCIP 第二天

MySQL (3)
随机推荐
Dataset:机器学习中常用数据集下载链接集合之详细攻略
typescript 'props' is declared but its value is never read solution
速看!PMP新考纲、PMBOK第七版解读
Summer Summary (3)
能与观众实时互动的Claper
Servlet
Leetcode周赛304
Servlet
Day 4 of HCIP
解决:- SPY: No data found for this date range, symbol may be delisted报错
[数据集][VOC]男女数据集voc格式6188张
Technology empowers Lhasa's "lungs", Huawei helps Lalu Wetland Smart Management to protect lucid waters and lush mountains
chrome plugin development guide
Mining game (C language)
(部分不懂,笔记整理未完成)【图论】差分约束
ue先视频教程后深入
C# FileInfo class
How does abaqus quickly import the assembly of other cae files?
July 18-July 31, 2022 (Ue4 video tutorials and documentation, 20 hours. Total 1412 hours, 8588 hours left)
实验7 MPLS实验