list = [yes, no, seven]
print ("What do you want to pull from the list?")
answer = input()
print (list[answer])
我该怎么做这种情况?我知道这个例子不起作用,但是如何使它成功呢?
编辑:我希望它是我输入的数字,0表示是,1表示否,2表示7表示可能
答案 0 :(得分:2)
您正在寻找dict
,而不是list
。
my_dictionary = {'yes':1, 'no':4, 'seven':9}
answer = input("What do you want to pull from the dictionary? ")
print(my_dictionary[answer])
答案 1 :(得分:0)
list_ = [yes, no, seven]
print ("What do you want to pull from the list?")
answer = input()
print (list_[list_.index(answer)])
答案 2 :(得分:0)