我放弃了之前的编码方式因为觉得太长了。选择下面这个方式
import random
num_card = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"]
num_color = ["梅花", "方块", "红桃", "黑桃"]
num = random.randint(1, 13)
num_2 = random.randint(1, 4)
print(f"The card you picked is the {num_card[num]} of {num_color[num_2]}")
运行结果
一次好一次坏。有的时候多次好,然后碰到一次坏。
在平台查了IndexError: list index out of range,自我理解是不是四个花色和13张牌他们之间列表的数目不一致,造成的这样的出错呢???
用了字典的方式。感觉并不是很满意。这个题先这样做下道题。



