I am currently working on this code:
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"])
And it works fine as it is, but to select a choice you input the number of the choice, which makes sense, but I would like for it to instead return the number they choose, the actual choice that goes with that number.
I am thinking that maybe something with a dictionary could work, or even just using the choice list provided, but I cannot figure it out, and help is appreciated.
choice is a list containing all the answers and N_C_input is a number as a string, which is associated to choice .
return choice[int(N_C_input)-1]
Returns the actual choice.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.