【发布时间】:2018-11-27 11:40:49
【问题描述】:
我目前正在处理此代码:
def N_C(question,choice):
N_C_choice_count_max = len(choice)
N_C_choice_count_min = N_C_choice_count_max - N_C_choice_count_max
N_C_restart_input = True
N_C_choices = []
print(question)
for i in range (N_C_choice_count_min,N_C_choice_count_max):
print(N_C_choice_count_min+i+1,":",choice[i])
str(N_C_choices.append(N_C_choice_count_min+i+1))
while N_C_restart_input == True:
N_C_input = input(">")
if str(N_C_input) in str(N_C_choices):
break
else:
continue
return(N_C_input)
N_C("question",["choice1","choice2","asmanychoicesasyouwant"])
它按原样工作得很好,但是要选择一个选项,你输入选项的编号,这是有道理的,但我希望它返回他们选择的数字,即与该数字相关的实际选择.
我在想也许有字典的东西可以工作,甚至只是使用提供的选择列表,但我无法弄清楚,不胜感激。
【问题讨论】:
标签: python function dictionary