About 613,000 results
Open links in new tab
  1. Print the Fibonacci sequencePython | GeeksforGeeks

    Mar 22, 2025 · This approach uses a while loop to print the first n Fibonacci numbers by repeatedly summing the previous two numbers. It starts with 0 and 1, and calculates the next number in the sequence until n terms are printed.

  2. Python Program to Print the Fibonacci sequence

    If the number of terms is more than 2, we use a while loop to find the next term in the sequence by adding the preceding two terms. We then interchange the variables (update it) and continue on with the process. You can also print the Fibonacci sequence using recursion.

  3. while loop - Fibonacci Sequence using Python - Stack Overflow

    May 8, 2013 · if n >= 0: for index_num in range(len(fibonacci_list)): if n == index_num: return fibonacci_list[index_num] else: return -1 if __name__ == '__main__': start_num = int(input()) print('fibonacci({}) is {}'.format(start_num, fibonacci(start_num)))

  4. Python Program to Print Fibonacci Numbers using While Loop

    In this tutorial, we are going to print Fibonacci numbers until a given number by using a while loop in Python. This program generates all the Fibonacci numbers up to a given number n using a while loop. print(a) a = b. b = a + b. # Print the current Fibonacci number. print(a) # Update a and b to generate the next Fibonacci number. a = b. b = a + b

  5. Fibonacci Series in Python using While Loop - StackHowTo

    Jun 25, 2021 · Fibonacci Series in Python using While Loop nterms = int(input("Enter a number: ")) n1 = 0 n2 = 1 print("\n The fibonacci sequence is :") print(n1, ",", n2, end=", ") for i in range(2, nterms): next = n1 + n2 print(next, end=", ") n1 = n2 n2 = next. This example will print the Fibonacci sequence of 10. Enter a number: 10 The fibonacci sequence ...

  6. Simple Ways to Generate Fibonacci Sequence in Python

    Apr 14, 2025 · You can use a loop, such as a for or while loop, to generate a Fibonacci sequence by iteratively adding the last two numbers in the sequence to produce the next number. Here’s a sample program using a while loop:

  7. python - Fibonacci Sequence - using While True - Stack Overflow

    Jul 6, 2018 · You've been shown a better Fibonacci function, but for learning purposes here's why yours isn't working. Let's look at your while loop. The first time through, you'll go through the if block. This sets num3 to 3, and then sets num2 to 3 as well. So your variables are (num, num2, num3) == (1, 3, 3).

  8. Generate Fibonacci Series in Python - PYnative

    Mar 27, 2025 · Explanation: The function initializes a and b with the first two Fibonacci numbers.; A while loop continues as long as the count is less than n.; Inside the loop, the next Fibonacci number is calculated and appended to the list. a and b are updated to prepare for the next iteration.; 3. Using Recursion. Recursion is a programming technique where a function calls itself to solve smaller ...

  9. Python Fibonacci Series program - Tutorial Gateway

    The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding ones. This blog post will show how to write a Python program to generate the Fibonacci Series of numbers using While Loop, For Loop, and Recursion. We will also explore finding the sum using loops.

  10. Fibonacci Series in Python: A Deep Dive - Simplilearn

    Nov 12, 2024 · There are many ways to write the Fibonacci series program in python for as many terms as you want. Let's look at some of the most popular ways. The simplest method is to use a for loop in Python to calculate and print each term in the Fibonacci sequence iteratively.

  11. Some results have been removed
Refresh