Program help (beginner)

Cliff Wells clifford.wells at comcast.net
Wed Oct 13 13:56:35 EDT 2004


On Wed, 2004-10-13 at 12:35 -0500, Borman, Linda E wrote:

> Program using a function and using "if, elif, else" 

This sounds suspiciously like a homework assignment.  Nevertheless, I
will provide a solution under one condition: never, ever post horrible,
giant green HTML to this or any other public list again.


def check_direction(direction):
    direction = direction.lower()
    if direction in ['north', 'south', 'east', 'west']:
        print 'You chose %s' % direction
        return direction
    else:
        print "You do not know where you want to go, huh!"
        return None
    
def location_description(direction):
    results = {
        'north': 'You must want to be cold',
        'south': 'You must want to be hot',
        'east':  'You must want to be where there might be rain',
        'west':  'You must want to be where there might be fog',
        }
    return results[direction]
 
   
print "\nPlease enter the destination of the area you would like to travel to." 
direction = raw_input("\nChoose North, South, West or East: ")

direction = check_direction(direction)
if not direction:
    raise SystemExit
 
raw_input("\n\nPlease hit enter to find out what to expect.")
print "\nHere are your results: %s\n" % location_description(direction)

raw_input ("Press the enter key to exit.")



-- 
Cliff Wells <clifford.wells at comcast.net>




More information about the Python-list mailing list