# -*- coding: utf-8 -*- # The line above with utf-8 in it tells Python and IDLE that our # file may have characters that are outside the ASCII character set. The # ñ in the word pequeño is one of those. # 10/27/2008 P. Conrad for CS5nm # These functions illustrate the use of if/else and if/elif/elif/else in # Python to make two way decisions, or decisions that are three or more ways. # Print name tag... assume that we have two fonts, and we can # tell the printer to use the big font by putting around the name, # while we can use the small font by putting around the name. # # We need to use if the name is larger than 5 characters in length. def printNameTag(name): if len(name) > 5: print "" + name + "" else: print "" + name + "" # Print name tag... we use "imprimeNameTag", which is Spanglish for printNameTag # (imprimir is the Spanich verb "to print", and "imprime" is the imperative) # We'll assume that we have three sizes: pequeño, grande and medio. # (small, larger, and half-way-in-between) # Now, names larger than 15 will print "error", while names between 8 and 14 # will print small, names 6 and 7 will print in medium, and names 5 or less # will print big. def imprimeNameTag(name): if len(name) > 15: print "error" elif len(name) > 5 and len(name) < 8: print "" + name + "" elif len(name) > 5: print "" + name + "" else: print "" + name + ""