Python Exercise: Fibonacci series between 0 to 50
Python Conditional: Exercise-9 with Solution
Write a Python program to get the Fibonacci series between 0 and 50.
Note : The Fibonacci Sequence is the series of numbers :
0, 1, 1, 2, 3, 5, 8, 13, 21, ....
Every next number is found by adding up the two numbers before it.
# Initialize variables 'x' and 'y' with values 0 and 1, respectively x, y = 0, 1 # Execute the while loop until the value of 'y' becomes greater than or equal to 50 while y < 50: # Print the current value of 'y' print(y) # Update the values of 'x' and 'y' using simultaneous assignment, # where 'x' becomes the previous value of 'y' and 'y' becomes the sum of 'x' and the previous value of 'y' x, y = y, x + y
1 1 2 3 5 8 13 21 34
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.
Next: Write a Python program which iterates the integers from 1 to 50. For multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join