Posts

Showing posts with the label Recursions: Recursive Vs Iterative Approach

Python Tutorial 22 --- "Recursions: Recursive Vs Iterative Approach"

Python Tutorial 22 ---  "Recursions: Recursive Vs Iterative Approach" This PROGRAM or TUTORIAL is about Python's "Recursions: Recursive Vs Iterative Approach" DOC: We have worked with iteration in previous lectures, related to loops, while recursion is a new topic for us. Let's start with the definition:            "Recursion occurs when a function calls itself." Mostly both recursion and iteration are used in association with loops, but both are very different from each other. In both recursion and iteration, the goal is to execute a statement again and again until a specific condition is fulfilled. An iterative loop ends when it has reached the end of its sequence; for example, if we are moving through a list, then the loop will stop executing when it reached the end of the list. But in the case of recursion, the function stops terminating when a base condition is satisfied. Let us understand both of them in detail. Recursion...

Python Quiz 5 --- "Fibonacci Series"

Python Quiz 5 --- "Fibonacci Series" The PROGRAM or TUTORIAL  is about a "Fibonacci Series" Fibonacci Series  -  The  Fibonacci sequence  is a set of  numbers  that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a  Fibonacci  number) is equal to the sum of the preceding two  numbers . ... F (0) = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ... SOLUTION: # Fibonacci Series # 0 1 1 2 3 5 8 13 def fibonacci (n): if n == 1 : return 0 elif n == 2 : return 1 else : return fibonacci(n - 1 ) + fibonacci(n - 2 ) number1 = int ( input ( "Enter then number \n " )) print (fibonacci(number1))