5 from __future__ import print_function
11 except NameError: # Python 3
15 def hmenu(prompt, astring):
17 Writes prompt and read result
18 until result[0] is one of allowed characters (from astring),
19 and returns the character
22 result = raw_input(prompt)
29 def vmenu(item_list, prompt, format = "%d. %s"):
31 Prints numbered list of items and allow user to select one,
32 returns selected number. Returns -1, if user enter non-numeric string.
34 for i in range(len(item_list)):
35 print(format % (i, item_list[i]))
38 result = raw_input(prompt)
49 result = hmenu("Select: d)aily, w)eekly, m)onthly, c)ancel: ", "dwmc")
50 print("Answer is '%s'\n" % result)
52 os_list = ["DOS", "Windows", "UNIX"]
53 result = vmenu(os_list, "Select OS: ")
54 if 0 <= result < len(os_list):
55 print("Answer is '%s'\n" % os_list[result])
57 print("Wrong selection")
59 if __name__ == "__main__":