4 Written by Broytman, Mar 1998. Copyright (C) 1997 PhiloSoft Design.
11 def hmenu(prompt, astring):
13 Writes prompt and read result
14 until result[0] is one of allowed characters (from astring),
15 and returns the character
18 result = raw_input(prompt)
25 def vmenu(item_list, prompt, format = "%d. %s"):
27 Prints numbered list of items and allow user to select one,
28 returns selected number. Returns -1, if user enter non-numeric string.
30 for i in range(len(item_list)):
31 print format % (i, item_list[i])
34 result = raw_input(prompt)
37 result = string.atoi(result)
38 except string.atoi_error:
45 result = hmenu("Select: d)aily, w)eekly, m)onthly, c)ancel: ", "dwmc")
46 print "Answer is '%s'\n" % result
48 os_list = ["DOS", "Windows", "UNIX"]
49 result = vmenu(os_list, "Select OS: ")
50 if 0 <= result < len(os_list):
51 print "Answer is '%s'\n" % os_list[result]
53 print "Wrong selection"
55 if __name__ == "__main__":