{1$我不知道怎么回事?在
campers = {'pb' : 'Pooder Bennet', 'jf' : 'Jupiter Fargo',
'rb' : 'Randy Buffet', 'bl' : 'Botany Lynn',
'bt' : 'Boris Tortavich', 'tn' : 'Trinda Noober',
'fj' : 'Freetus Jaunders', 'nt' : 'Ninar Tetris',
'gm' : 'Gloobin Marfo', 'nk' : 'Niche Kaguya',
'bd' : 'Brent Drago', 'vt' : 'Volga Toober',
'kt' : 'Kinser Talebearing', 'br' : 'Bnola Rae',
'nb' : 'Nugget Beano', 'yk' : 'Yeldstat Krong',
'gy' : 'Gelliot Yabelor', 'il' : 'Illetia Dorfson',
'ct' : 'Can Tabber', 'tv' : 'Trinoba Vyder'}
campers_outside_theater = random.sample(campers.keys(), 5)
people = campers_outside_theater + ['Troid, the counselor from the bus.']
choices = '\n\n'.join('%d. %s' % (i + 1, campers[p]) for (i, p) in enumerate(people))
这将为您提供您想要的:
你有
keys(people)
,但没有这样的动物-这是你的第一个错误。它不是KeyError
,而是NameError
(因为keys
从未定义)。然后,当我删除了键并得到enumerate(people)
时,你得到了一个实际的键错误,因为你试图用'Troid, the counselor from the bus.'
作为键。。。但它不是一个。我假设你想把他包括在车上的人中,但你必须用另一种方式。也许把他包括在你的露营者字典里,在你随机抽取样本后,总是把他加到你的钥匙里。在这一行是导致错误的原因:
原因就在于这一行:
^{pr2}$字典
campers
中没有名为Troid, the counselor from the bus.
要解决此问题:
相关问题 更多 >
编程相关推荐