开发者

Python: Random item from list combining only two

开发者 https://www.devze.com 2023-03-30 18:54 出处:网络
I\'m making a slot machine program in Python and for some reason, the random selector wants to combine a known two elements.

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

精彩评论

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