I want to third the whitespace and comments.

Also, looking at your code I notice that each of your

while 1:
play = raw_input("What is your choice? ") #Aks use to enter a choice
from the menu
if play == '3': #If user picks 3
print "\nHave a nice day!\n" #Tell them to have a nice day
sys.exit() #Then exit the entire thing
elif play == '2': #If user picks 2
instruct() #Then lets call the instructions function
elif play == '1': #If user picks 1
game() #Then lets call the game function for the user to play
elif play == '': #This is used is the menu leaves the screen so the
user can get it back
choice() #Bring back the menu
else:
print "\nYou need to pick 1, 2 or 3 or hit enter to see choices\n"

results from the choice are basically functions and functions are objects, so....
(I got this idea from Danny and Kent - I like it...)



def exit():
print "\nHave a nice day!\n" # You might want to make this a raw_input so the
sys.exit() # user can catch it before the screen disappears...


def altexit(): # Alternative exit
raw_input("\nHave a nice day!\nPress enter to exit.") # This stops the exit just long enough for the user to press enter and leave
sys.exit()


def instruct():
   ## Whatever instruct is, goes here

def game():
   ## The game function is here

def choice():
   ## The choice definition is here

## Now the fun part ##
## We define a dictionary options that stores the strings that the user would input as keys. The values
## are the functions that we just defined


options = {"3":altexit, # Notice no parenthesis--we don't want to call the functions when putting them in the dicionary!
"2":instruct,
"1":game,
"":choice}


while 1:
play = raw_input("What is your choice? ")
if play in options.keys(): ## This makes sure that the user input is one of our options
options[play]() ## Call the function that is the value of the key that is the choice the user made
else: ## Say that the user input is not one of your choices...
print "\nYou need to pick 1, 2 or 3 or hit enter to see choices\n"


HTH,
Jacob


_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Reply via email to