On 17/01/15 02:00, Alan Gauld wrote:
Here is a very simple example modelled on your description
#####################
def readMenu(menu):
while not (1<= choice <= len(menu) ):
for index, item in enumerate(menu,start=1):
print (index, item)
choice = input("\nchoose an item: ")
return choice-1
Oops, a couple of bugs in there, here is a working version
def readMenu(menu):
choice = 0
while not (1<= choice <= len(menu) ):
for index, item in enumerate(menu,start=1):
print (index, item)
choice = int(input("\nchoose an item: "))
return choice-1
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor