当前位置:网站首页>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)
边栏推荐
- Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
- Bootloader implementation of PIC MCU
- On boost circuit
- VESC Benjamin test motor parameters
- Talk about the circuit use of TVs tube
- MySQL之MHA高可用集群
- Use indent to format code
- H264 (I) i/p/b frame gop/idr/ and other parameters
- Sql Server的存儲過程詳解
- Detailed summary of FIO test hard disk performance parameters and examples (with source code)
猜你喜欢

H264 (I) i/p/b frame gop/idr/ and other parameters

STM32 single chip microcomputer -- volatile keyword

Negative pressure generation of buck-boost circuit

Step motor generates S-curve upper computer

C language # and #
![Halcon's practice based on shape template matching [2]](/img/70/3e905661785e570fb406b8e97d41e6.jpg)
Halcon's practice based on shape template matching [2]

How to write cover letter?

DokuWiki deployment notes

MySQL之MHA高可用集群
![[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl](/img/8a/702019b44c8e60dffbcd898330afcb.png)
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
随机推荐
Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
实例009:暂停一秒输出
Negative pressure generation of buck-boost circuit
Various types of questions judged by prime numbers within 100 (C language)
如何写Cover Letter?
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
Hardware and software solution of FPGA key chattering elimination
Why is 1900 not a leap year
Explication de la procédure stockée pour SQL Server
Ble encryption details
Take you to understand the working principle of lithium battery protection board
[three tier architecture and JDBC summary]
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
Working principle and type selection of common mode inductor
Weidongshan Internet of things learning lesson 1
Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev
Synchronization of QT multithreading
Verilog -- state machine coding method
Let's briefly talk about the chips commonly used in mobile phones - OVP chips
Introduction of air gap, etc