当前位置:网站首页>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)
边栏推荐
- Sql Server的存储过程详解
- C WinForm [realize the previous and next selection pictures] - practice 7
- 实例008:九九乘法表
- Talk about the function of magnetic beads in circuits
- Nb-iot technical summary
- Sql Server的存儲過程詳解
- After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
- Solutions to compilation warnings in Quartus II
- matlab timeserise
- 实例006:斐波那契数列
猜你喜欢
STM32 single chip microcomputer - external interrupt
List of linked lists
Step motor generates S-curve upper computer
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Volatile of C language
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
Explain task scheduling based on Cortex-M3 in detail (Part 2)
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
STM32 --- serial port communication
Simple design description of MIC circuit of ECM mobile phone
随机推荐
Charge pump boost principle - this article will give you a simple understanding
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
Design a clock frequency division circuit that can be switched arbitrarily
What are the test items of power battery ul2580
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
C WinForm [view status bar -- statusstrip] - Practice 2
Ble encryption details
Sql Server的存储过程详解
Google sitemap files for rails Projects - Google sitemap files for rails projects
matlab timeserise
Various types of questions judged by prime numbers within 100 (C language)
【三层架构及JDBC总结】
Void* C is a carrier for realizing polymorphism
General makefile (I) single C language compilation template
Nb-iot technical summary
Adaptive filter
[three tier architecture and JDBC summary]
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc