InteractiveDecisionMaker uses alphabet characters to identify choices (less confusing, because model elements often already include numbers)
This commit is contained in:
parent
c9c5a5214d
commit
87fdb8c190
1 changed files with 2 additions and 2 deletions
|
|
@ -42,7 +42,7 @@ class InteractiveDecisionMaker(DecisionMaker):
|
||||||
def __call__(self, actions):
|
def __call__(self, actions):
|
||||||
arr = []
|
arr = []
|
||||||
for i, (key, result) in enumerate(actions):
|
for i, (key, result) in enumerate(actions):
|
||||||
print(f" {i}. {key}")
|
print(f" {chr(97+i)}. {key}")
|
||||||
arr.append(result)
|
arr.append(result)
|
||||||
if len(arr) == 0:
|
if len(arr) == 0:
|
||||||
return
|
return
|
||||||
|
|
@ -53,7 +53,7 @@ class InteractiveDecisionMaker(DecisionMaker):
|
||||||
sys.stdout.write(f"{self.msg} ")
|
sys.stdout.write(f"{self.msg} ")
|
||||||
try:
|
try:
|
||||||
raw = input()
|
raw = input()
|
||||||
choice = int(raw) # may raise ValueError
|
choice = int(ord(raw)-97) # may raise ValueError
|
||||||
if choice >= 0 and choice < len(arr):
|
if choice >= 0 and choice < len(arr):
|
||||||
return arr[choice]
|
return arr[choice]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue