大白菜豆腐 2023-03-17 13:55 采纳率: 100%
浏览 26
已结题

关于#Python#的问题,如何解决?

img

img

img


第一题是计算天数,第二题是求扑克牌的排序,第三张图是第二道题的翻译,用Python答题

  • 写回答

4条回答 默认 最新

  • 关注

    如下:

    import random
    value=['A','2','3','4','5','6','7','8','9','10','J','Q','K']
    color=['Spades','hearts','plum blossoms','diamonds']
    
    cards = value*4
    cards.append('SKing')
    cards.append('BKing')
    
    res=[]
    while len(res) < 5: # 取5张牌
        index = random.randint(0,len(cards))
        if index == 52:
            res.append('SKing')
        elif index == 53:
            res.append('BKing')
        else:
            c = int(index/13)
            v = index - 13*c
            ak =[]
            ak.append(color[c])
            ak.append(value[v])
            s = ' '.join(ak)
            if s not in res:
                res.append(s)
    
    print(res)
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 4月5日
  • 已采纳回答 3月28日
  • 创建了问题 3月17日