0

我正在尝试从 5 个不同的用户选择列表中打印一个数字。
这是代码

import random

d = {'january':['1', '2', '3', '4', '5', '6', '7']
,'febuary':['1', '2', '3', '4', '5', '6', '7']
,'march':['1', '2', '3', '4', '5', '6', '7']
,'april':['1', '2', '3', '4', '5', '6', '7']
,'may':['1', '2', '3', '4', '5', '6', '7']
,'june':['1', '2', '3', '4', '5', '6', '7']
,'july':['1', '2', '3', '4', '5', '6', '7']
,'august':['1', '2', '3', '4', '5', '6', '7']}

items = raw_input("Pick 5 and separate them by a comma:" + ','.join(d)
item1, item2, item3, item4, item5 = items.split(',')

print 'picked:', random.choice(d[item1])

print 'picked:', random.choice(d[item2])

print 'picked:', random.choice(d[item3])

print 'picked:', random.choice(d[item4])

print 'picked:', random.choice(d[item5])

raw_input ()

我不断得到一个

SyntaxError on line 13;
    item1, item2, item3, item4, item5 = items.split(',')

我也试过

items = raw_input("Pick 5 separated by comma:" + ','.join(d)
splitItems = items.split(',')

#print roles

print 'picked:', random.choice(d[splitItems[0]])
print 'picked:', random.choice(d[splitItems[1]])
print 'picked:', random.choice(d[splitItems[2]])
print 'picked:', random.choice(d[splitItems[3]])
print 'picked:', random.choice(d[splitItems[4]])

这也有一个

SyntaxError on line 13;
    splitItems = items.split(',')

编辑:修正错误

4

1 回答 1

0

你在结束时缺少一个接近的括号

items = raw_input("Pick 5 and separate them by a comma:" + ','.join(d)
于 2013-01-30T11:21:59.447 回答