Write a python script to print Fibonacci series first 20 elements
Answers
Answered by
26
A python script to print Fibonacci series first 20 elements:
numterms = int(input("How many terms? ")) #to get number of terms at run time
# Initialize the first two terms
num1 = 0
num2 = 1
cntt = 0
if numterms <= 0:
print("Enter only a positive integer")
elif numterms == 1:
print("Fibonacci sequence upto",numterms,":")
print(num1)
else:
print("Fibonacci sequence upto",numterms,":")
while count < numterms:
print(num1,end=' , ')
nth = num1 + num2
num1 = num2
num2 = nth
cntt += 1
Answered by
3
Answer:
Fibonacci Sequence of first 20 elements
Explanation:
first=0
second=1
print(first)
print(second)
for a in range(1,19):
third=first+second
print(third)
first,second=second,third
Similar questions