当前位置:网站首页>计算序列之和
计算序列之和
2022-07-02 07:23:00 【算法与编程之美】
问题描述
有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
示例:
输入:输入前二十项,并取两位小数。
输出:32.66
2.算法描述
给定两个起始数,分别赋值,然后套入循环里面,根据规律,分子为上一组分子和分母这个,并递推,直到第二十项,最后求和,得出结果。
3.实验讨论与结果
找出规律,并根据规律写循环,再写出程序。
a=1 b=2 s=0 for I in range(1,21): s+=b/a a , b=b , b +a print(s) print('=%.2f'%s) |
四.结语
这道题主要考虑的就是找出分子和分母的规律,并且套入循环,计算然后得出结果。
边栏推荐
猜你喜欢
12. Process synchronization and semaphore
Analysis of hot spots in AI technology industry
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
【AppLinking实战案例】通过AppLinking分享应用内图片
[TS] 1368 seconds understand typescript generic tool types!
Is this code PHP MySQL redundant?
2022爱分析· 国央企数字化厂商全景报告
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
全网显示 IP 归属地,是怎么实现的?
从.bag文件中读取并保存.jpg图片和.pcd点云
随机推荐
Shell programming 01_ Shell foundation
洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
简洁、快速、节约内存的Excel处理工具EasyExcel
(五)APA场景搭建之挡位控制设置
axis设备的rtsp setup头中的url不能带参
session-cookie与token
How to get the password of cpolar?
[SUCTF2018]followme
618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
长投学堂上面的账户安全吗?
HDU1228 A + B(map映射)
Kustomize user manual
PCL 从一个点云中提取一个子集
【快应用】Win7系统使用华为IDE无法运行和调试项目
Hdu1228 a + B (map mapping)
Shapiro Wilk normal analysis by SPSS
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
Analysis of hot spots in AI technology industry
力扣(LeetCode)182. 查找重复的电子邮箱(2022.07.01)
2022-06-17