开发者

Python: Random item from list combining only two

I'm making a slot machine program in Python and for some reason, the random selector wants to combine a known two elements.

    itmlist = random.choice(['banana', 'cherry', 'bar', 'seven', 'banana', 'cherry' 'banana', 'cherry', 'seven'])
    print itmlist

It shows up as "cherrybanana" every once in a while and I am开发者_JAVA技巧 really confused.


You miss a comma between 'cherry' and 'banana' near the end of the list.

Python concatenate the strings so it becomes 'cherrybanana'

itmlist = random.choice(['banana', 'cherry', 'bar', 'seven', 'banana', 'cherry' 'banana', 'cherry', 'seven'])

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜