[Tutor] Done at Last!

Lloyd Hugh Allen lha2@columbia.edu
Mon, 26 Mar 2001 18:48:17 -0500


> Message: 7
> From: "Britt Green" <britt_green@hotmail.com>
> To: tutor@python.org
> Date: Mon, 26 Mar 2001 11:50:50 -0800
> Subject: [Tutor] Done at Last!
> 
> Alright. I'm done with my first program. It works...most of the time! :) I
> would really appreciate some feedback on it 
[snip]
>     try:
>         answer = input("-->")
> 
>         if answer == 1:
>             ftpdirs = ['atl/']
>             return ftpdirs
>         elif answer == 2:
>             ftpdirs = ['boston/']
>             return ftpdirs
>         elif answer == 3:
>             ftpdirs = ['chicago/']
>             return ftpdirs
>         elif answer == 4:
>             ftpdirs = ['dc/']
>             return ftpdirs
>         elif answer == 5:
>             ftpdirs = ['la/']
>             return ftpdirs
>         elif answer == 6:
>             ftpdirs = ['miami/']
>             return ftpdirs
>         elif answer == 7:
>             ftpdirs = ['nola/']
>             return ftpdirs
>         elif answer == 8:
>             ftpdirs = ['ny/']
>             return ftpdirs
>         elif answer == 9:
>             ftpdirs = ['phl/']
>             return ftpdirs
>         elif answer == 10:
>             ftpdirs = ['portland/', 'Vail/']
>             return ftpdirs
>         elif answer == 11:
>             ftpdirs = ['sd/']
>             return ftpdirs
>         elif answer == 12:
>             ftpdirs = ['seattle/']
>             return ftpdirs
>         elif answer == 13:
>             ftpdirs = ['sf/']
>             return ftpdirs
>         elif answer == 14:
>             ftpdirs = ['slc/']
>             return ftpdirs
>         elif answer == 15:
>             ftpdirs = ['austin/', 'dallas/', 'galveston/', 'houston/']
>             return ftpdirs
>         elif answer == 16:
>             ftpdirs = choices
>             return ftpdirs
>         else:
>             print "Lets choose a number in the menu, sparky!"
>             makeChoice()

for this chunk, I think you can implement a dictionary; maybe something
along the lines of

	ftpdirs = {1:['atl/'], 2:['boston/'], #etcetc#, 15:['austin/',
'dallas/', 		'galveston/', 'houston'], 16:choices} # up high in the code

and then where you have all those elifs:

	return ftpdirs[answer]

if that makes any sense, and if no one else said the same thing while I
was waiting for digest form to digest.