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