Fibonacci Number (first 30) Python

2023-01-12   ES  

First define recursive function:

# definition recursive function 
 DEF FI (n): 
     # A = 0 
         if n> 0: 
             if n == 1 or n == 2: 
                 Return 1 
                 Return Fi (N-1)+Fi (N-2) 
             Print ("You Must input a Number> = 0")

Then the for loop:

# For a for loop 
     for I in Range (1, N+1): 
         Print (fi (i)) 
 fiprint (30)

Last result printing:

# print results 
 a = fi (30) 
 Print (a)

Here adding a circular program running time calculation:

#The cycle program running time 
 end_time = time () 
 run_time = end_time-begin_time 
 Print ('The cycle program runs:', run_time)

Implementation effect:


Random Posts

Uboot transplant 1: Overall browsing wenlong

LinuxPCI driver Get the designated device Bus, Device, and DeVFN data method

STM32 HAL engineering KE architecture

Computer has developed for so many years, why did you have not been able to lean out the life of the mouse?

Graphviz Simple Drawing (Python)