﻿ Python Exercise: Fibonacci series between 0 to 50 - w3resource

# 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.

Pictorial Presentation:

Sample Solution:

Python Code:

``````# 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
```
```

Sample Output:

```1
1
2
3
5
8
13
21
34
```

Flowchart:

Python Code Editor :

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿