Python Introduction


Python is a general-purpose programming language that can be used on any modern computer operating system. It can be used for processing text, numbers, images, scientific data and just about anything else you might save on a computer. It is used daily in the operations of the Google search engine, the video-sharing website YouTube, NASA and the New York Stock Exchange. These are but a few of the places where Python plays important roles in the success of the business, government, and non-profit organizations; there are many others.

Why Python?
  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
  • Python has a simple syntax similar to the English language.
Python Syntax Compared to Other Programming Languages
no =    

     
~/public_html/cgi-bin/101/9/Fib/Fib.py (simplified)
#!/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


Review: Python Programming Language
    Which statement is NOT true about Python programming language?

      Python expresses the logic of a computation without describing its control flow.
      Python relies on indentation, using whitespace, to define scope.
      Python runs on an interpreter system.
      Python uses new lines to complete a command.
Result: