Python-First 10 Fibonacci Numbers

Write a program to compute and print the first 10 Fibonacci numbers.

#Fibonacci numbers
#To print the first 10 Fibonacci numbers
#Fibonacci numbers are an infinite series of numbers in which
#the first two numbers are 1 and 1. Every successive number
#is the sum of the previous two numbers
#The first two numbers are also taken as 0 and 1

a = 1
b = 1
ctr = 2 #this indicates that we have two numbers so far

#print the first two Fibonacci numbers
print (a, end = ' ')  #end = ' ' means print value of a & stay on same line
print (b, end = ' ')

#Now compute and print the remaining Fibonacci numbers
while ctr < 10:
      sum = a + b
      print (sum, end = ' ')
      ctr += 1    #every time a new Fibonacci number is printed, increment counter
      a = b 
      b = sum
#EOWhileLoop      

#End of program
Advertisements