8 def hmenu(prompt, astring):
10 Writes prompt and read result
11 until result[0] is one of allowed characters (from astring),
12 and returns the character
15 result = raw_input(prompt)
22 def vmenu(item_list, prompt, format = "%d. %s"):
24 Prints numbered list of items and allow user to select one,
25 returns selected number. Returns -1, if user enter non-numeric string.
27 for i in range(len(item_list)):
28 print format % (i, item_list[i])
31 result = raw_input(prompt)
34 result = string.atoi(result)
35 except string.atoi_error:
42 result = hmenu("Select: d)aily, w)eekly, m)onthly, c)ancel: ", "dwmc")
43 print "Answer is '%s'\n" % result
45 os_list = ["DOS", "Windows", "UNIX"]
46 result = vmenu(os_list, "Select OS: ")
47 if 0 <= result < len(os_list):
48 print "Answer is '%s'\n" % os_list[result]
50 print "Wrong selection"
52 if __name__ == "__main__":