当前位置:网站首页>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)
边栏推荐
- How to write cover letter?
- STM32 single chip microcomputer -- debug in keil5 cannot enter the main function
- Sql Server的存儲過程詳解
- Hardware 1 -- relationship between gain and magnification
- STM32 single chip microcomputer - external interrupt
- Sword finger offer 09 Implementing queues with two stacks
- Void* C is a carrier for realizing polymorphism
- Soem EtherCAT source code analysis II (list of known configuration information)
- Step motor generates S-curve upper computer
- MySQL之MHA高可用集群
猜你喜欢
Hardware 3 -- function of voltage follower
STM32 single chip microcomputer - external interrupt
Talk about the function of magnetic beads in circuits
Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
Ble encryption details
Stablq of linked list
Relationship between line voltage and phase voltage, line current and phase current
Explain task scheduling based on Cortex-M3 in detail (Part 1)
MySQL之MHA高可用集群
随机推荐
Explication de la procédure stockée pour SQL Server
Stablq of linked list
My-basic application 1: introduction to my-basic parser
Explain task scheduling based on Cortex-M3 in detail (Part 2)
动力电池UL2580测试项目包括哪些
Let's briefly talk about the chips commonly used in mobile phones - OVP chips
Several important parameters of LDO circuit design and type selection
Shell script realizes the reading of serial port and the parsing of message
Count the number of inputs (C language)
Management and use of DokuWiki (supplementary)
Solutions to compilation warnings in Quartus II
STM32 --- configuration of external interrupt
Ble encryption details
Carrier period, electrical speed, carrier period variation
Vofa+ software usage record
Circleq of linked list
STM32---ADC
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
亿学学堂给的证券账户安不安全?哪里可以开户
WiFi wpa_ Detailed description of supplicant hostpad interface