-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
29 lines (23 loc) · 845 Bytes
/
menu.py
File metadata and controls
29 lines (23 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Menu:
def __init__(self, options):
self.options = options
self.opt_amount = len(options)
self.select = ""
self.state = 0 # 0 - Inputting, 1 - Success, 2 - Failed
self.reason = ""
def query(self):
self.select = ""
self.state = 0
print("\n\nSelect one of the following:")
for i in range(self.opt_amount):
print(str(i + 1) + ". " + self.options[i])
self.select = input("\n.: ")
if (not self.select.isdigit()):
self.state = 2
self.reason = "Invalid option selected"
return
if (int(self.select) < 0 or int(self.select) >= (self.opt_amount + 1)):
self.state = 2
self.reason = "Invalid option selected"
return
self.state = 1