In: Computer Science
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
#fnum and snum initialized
fnum = 0;
snum = 1;
#printing fnum and snum
print(fnum,end = ",")
print(snum,end = ",")
#for loop will iterate
#range is starting from 2 because 2 numbers already printed
#100 is excluded,because we don't want "," after 100th number
#so, printing 100th value after loop
for i in range(2,100):
#snum is stored in temp
temp = snum
#snum + fnum is stored in snum
snum = snum + fnum
#temp is stored in fnum
fnum = temp
#printing snum
print(snum,end = ",")
#printing 100th number in the series
print(snum + fnum)
#code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!