[英]Python - 5 random items from user chosen lists in dictionary
I am trying to print one number from 5 different user chosen lists. 我正在尝试从5个不同的用户选择列表中打印一个数字。
This is the code 这是代码
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 ()
I keep getting a 我不断得到
SyntaxError on line 13;
item1, item2, item3, item4, item5 = items.split(',')
I have also tried 我也尝试过
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]])
which also had a 其中也有一个
SyntaxError on line 13;
splitItems = items.split(',')
Edit: fixing mistakes 编辑:修复错误
您在末尾缺少亲密伙伴
items = raw_input("Pick 5 and separate them by a comma:" + ','.join(d)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.