当前位置:网站首页>Example 006: Fibonacci series
Example 006: Fibonacci series
2022-07-05 08:22:00 【Lazy smile】
example 006: Fibonacci sequence
subject : Fibonacci sequence . Output Fibonacci sequence of a given number .
# Topic analysis : Fibonacci sequence (Fibonacci sequence), from 1,1 Start , Each of the latter is equal to the sum of the first two .
# Program analysis : We can define a list to store Fibonacci series , According to the law of Fibonacci sequence , From 3 A start , Each item is the sum of the first two items , Get the sum of the first two items and store it in the sequence .
# When you first enter i=0 When ,a=1,b=a+b=2, When i=1 when ,a=2,b=a+b=3, When i=2 when ,a=3,b=a+b=5,·······
list_fib = [1] # Define a list to store Fibo's number series , Initialize the value of the first element as 1
target = int(input(" Enter the perbonacci sequence of the first few items you want "))
res = 0
a, b = 1, 1
for i in range(target - 1):
a, b = b, a + b
list_fib.append(a)
print(list_fib)Add the above paragraph to the cycle, and we can test it many times to see the effect :
for j in range(5):
list_fib = [1] # Define a list to store Fibo's number series , Initialize the value of the first element as 1
target = int(input(" Enter the perbonacci sequence of the first few items you want "))
res = 0
a, b = 1, 1
for i in range(target - 1):
a, b = b, a + b
list_fib.append(a)
print(list_fib)
边栏推荐
- 实例010:给人看的时间
- [trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
- Wifi-802.11 negotiation rate table
- Sword finger offer 09 Implementing queues with two stacks
- 关于线性稳压器的五个设计细节
- Google sitemap files for rails Projects - Google sitemap files for rails projects
- H264 (I) i/p/b frame gop/idr/ and other parameters
- Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
- STM32 --- GPIO configuration & GPIO related library functions
- Synchronization of QT multithreading
猜你喜欢
![[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture](/img/c5/22c6148873508b9205972e1ad970a3.jpg)
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
![Measurement fitting based on Halcon learning [i] fuse Hdev routine](/img/91/34c92065e797c87d6ce5ea13903993.jpg)
Measurement fitting based on Halcon learning [i] fuse Hdev routine

Solutions to compilation warnings in Quartus II

Ble encryption details
![[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication](/img/08/7f28008a4aa999650998ba8dee5d8e.jpg)
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication

Class of color image processing based on Halcon learning_ ndim_ norm. hdev

How to copy formatted notepad++ text?

More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!

Shell script

DCDC circuit - function of bootstrap capacitor
随机推荐
Ble encryption details
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
OC and OD gate circuit
Solutions to compilation warnings in Quartus II
Working principle and type selection of common mode inductor
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Synchronization of QT multithreading
How to copy formatted notepad++ text?
Compilation warning solution sorting in Quartus II
Briefly talk about the identification protocol of mobile port -bc1.2
实例008:九九乘法表
Why is 1900 not a leap year
Explain task scheduling based on Cortex-M3 in detail (Part 2)
Summary -st2.0 Hall angle estimation
STM32 --- GPIO configuration & GPIO related library functions
实例006:斐波那契数列
STM32 --- NVIC interrupt
WiFi wpa_ Detailed description of supplicant hostpad interface
Measurement fitting based on Halcon learning [III] PM_ measure_ board. Hdev routine
关于线性稳压器的五个设计细节