我想知道是否有可能运行下面的代码,同时将结果值捕获到一个变量中。代码如下:
def nodupchoice():
# For loop that creates a list named keys. It grabs 3 random keys from the dictionary word_drills
keys = [x for x in random.sample(word_drills, 3)]
# User is presented with a question. A value from the previous randomly selected keys is selected as the 'question'
print "Question: ", word_drills[random.choice(keys)]
# Set the variables key1, key2, & key3 to the 3 keys in the list 'keys'
key1, key2, key3 = keys[0], keys[1], keys[2]
# User is presented with 3 choices.
print "\n\n(a)%s (b)%s (c)%s" % (key1, key2, key3)
selection = raw_input("> ")
print selection
print correctvalue
代码行是打印“问题:”,单词\u[随机选择(键)]。我想把这个结果放到一个变量中,然后运行if/else语句,看看答案是否正确。再次感谢。你知道吗
呃,是吗?只需将其赋给一个变量:
现在变量
question
稍后仍然可用。你知道吗相关问题 更多 >
编程相关推荐