5 from __future__ import print_function
9 def hmenu(prompt, astring):
11 Writes prompt and read result
12 until result[0] is one of allowed characters (from astring),
13 and returns the character
16 result = raw_input(prompt)
23 def vmenu(item_list, prompt, format = "%d. %s"):
25 Prints numbered list of items and allow user to select one,
26 returns selected number. Returns -1, if user enter non-numeric string.
28 for i in range(len(item_list)):
29 print(format % (i, item_list[i]))
32 result = raw_input(prompt)
35 result = string.atoi(result)
36 except string.atoi_error:
43 result = hmenu("Select: d)aily, w)eekly, m)onthly, c)ancel: ", "dwmc")
44 print("Answer is '%s'\n" % result)
46 os_list = ["DOS", "Windows", "UNIX"]
47 result = vmenu(os_list, "Select OS: ")
48 if 0 <= result < len(os_list):
49 print("Answer is '%s'\n" % os_list[result])
51 print("Wrong selection")
53 if __name__ == "__main__":