1. Home
  2. Computing & Technology
  3. Python

"Merry Christmas!": A Quick Tour of Python

From , former About.com Guide

6 of 7

The main() Thing

Next, make a main() function:

def main():
salut = Felicitations()

hol_type = caps(hol)
lang_choice = caps(lang)
addressee = caps(addr)

if lang_choice == "French":
language = 1
elif lang_choice == "German":
language = 2
else:
language = 0

greeting = holiday(hol_type, language)

day = greeting[0]
salutation = greeting[1]

saludos = salutation + " " + day

salut.addon(saludos)
salut.addon(", ")

salut.addon(addressee)

salut.addon(punctuation)

prints(salut)

Several things happen in this function:

  1. We create an instance of the 'Felicitations' class and call it 'salut'. This allows us to access the parts of 'Felicitations' as they exist in 'salut'.
  2. Next, we capitalise the holiday, language and addressee variables using the function caps().
  3. Depending on the language choice, we assign a number to language which corresponds to the item in the dictionary (associative array) of function holiday().
  4. Function holiday() is then called with hol_type and language as arguments. The tuple that is returned will be assigned to variable greeting.
  5. The values of the tuple are then assigned to day and salutation respectively.
  6. These are then concatenated with "+", including a space between them. The next line appends them to object salut.
  7. In rapid succession, the folowing are appended to object salut by the following three lines: a comma (to offset the vocative address), the addressee, and the punctuation.
  8. Finally, the object 'salut' is sent to function prints to be printed to the screen.

Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.