Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Menu/Python/menu.py
Normal file
26
Task/Menu/Python/menu.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
def _menu(items):
|
||||
for indexitem in enumerate(items):
|
||||
print (" %2i) %s" % indexitem)
|
||||
|
||||
def _ok(reply, itemcount):
|
||||
try:
|
||||
n = int(reply)
|
||||
return 0 <= n < itemcount
|
||||
except:
|
||||
return False
|
||||
|
||||
def selector(items, prompt):
|
||||
'Prompt to select an item from the items'
|
||||
if not items: return ''
|
||||
reply = -1
|
||||
itemcount = len(items)
|
||||
while not _ok(reply, itemcount):
|
||||
_menu(items)
|
||||
# Use input instead of raw_input for Python 3.x
|
||||
reply = raw_input(prompt).strip()
|
||||
return items[int(reply)]
|
||||
|
||||
if __name__ == '__main__':
|
||||
items = ['fee fie', 'huff and puff', 'mirror mirror', 'tick tock']
|
||||
item = selector(items, 'Which is from the three pigs: ')
|
||||
print ("You chose: " + item)
|
||||
Loading…
Add table
Add a link
Reference in a new issue