Problem 2
2024-09-07 07:38:42
Problem 2
# Problem_2.py
"""
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
四百万以下的偶数斐波那契数列之和
"""
def fibonacci(x=1, y=1, end=10000):
if x >= end:
return []
else:
return [x] + fibonacci(y, x+y, end) fib = fibonacci(end=4000000)
print(fib)
num = sum([i for i in fib if i%2==0])
print(num)
最新文章
- Swift - 语言指南,来自github学习
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
- 查看Sql Server所有表占用的空间大小
- Java基础之写文件——使用带缓冲的Writer写文件(WriterOutputToFile)
- 项目解析- JspLibrary - part2
- DJANGO变动库的一次真实手动经历
- Ineligible Devices 不被识别的设备
- jqueryMobile中select样式自定义
- OpenCms创建站点过程图解——献给OpenCms的刚開始学习的人们
- input 和raw_input
- BZOJ2720: [Violet 5]列队春游
- grub2详解(翻译和整理官方手册)
- CSS的box-sizing属性
- VS2008下QT开发环境搭建(转)
- java返回数据工具类
- C# 计算地图上某个坐标点的是否在多边形内
- linux 安装nvm,通过nvm安装node
- 数据库SQLserver(课本)
- ROC,AUC,Precision,Recall,F1的介绍与计算
- 用例设计之API用例覆盖准则
热门文章
- oc4--方法
- 深入解析Dropout——基本思想:以概率P舍弃部分神经元,其它神经元以概率q=1-p被保留,舍去的神经元的输出都被设置为零
- CodeForces--621A--Wet Shark and Odd and Even(数学水题)
- 软件开发 —— 重构(refactor)
- Could not open ServletContext resource [/WEB-INF/Dispatcher-servlet.xml]
- 百度jquery公共引用地址
- NOIP2013 D2T1 积木大赛
- C# How to convert MessageBodyStream to MemoryStream?
- 豆瓣项目(用react+webpack)
- 如何在Hexo中实现自适应响应式相册功能