Why Python?
|
|
|
#!/usr/bin/python
#
# Python program to print Fibonacci numbers
# 0 1 1 2 3 5 8 13 21 34 55 89 ...
# where the 3rd number is the sum of the previous 2 numbers.
#
import cgi # CGI module
form = cgi.FieldStorage( ) # Reads the HTML form data.
act = form["act"].value
no = form["no" ].value
if ( act == "Print Fibonacci numbers" ):
# Print HTML.
print( "Content-type: text/html\n\n" )
a = 0
b = 1
no = int( no )
if ( no <= 2 ):
print( "The first 2 numbers are 0 and 1." )
else:
i = 0
while ( i < no ):
print( a )
c = a + b
a = b
b = c
i += 1
|
| Don’t count your chickens before they hatch. |