码迷,mamicode.com
首页 > 其他好文 > 详细

随机生成一副扑克

时间:2014-07-29 11:04:46      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   for   art   div   ar   

#Card.py

import random

class Card:
    def __init__(self,suit_id,rank_id):
        self.rank_id = rank_id
        self.suit_id = suit_id

        if self.rank_id == 1:
            self.rank = "Ace"
            self.value = 1
        elif self.rank_id == 11:
            self.rank = "Jack"
            self.value = 10
        elif self.rank_id == 12:
            self.rank = "Queen"
            self.value = 10
        elif self.rank_id == 13:
            self.rank = "King"
            self.value = 10
        elif 2<=self.rank_id <= 10:
            self.rank = str(self.rank_id)
            self.value = self.rank_id
        else:
            self.rankk = "RankError"
            self.value = -1

        if self.suit_id == 1:
            self.suit = "Diamonds"
        elif self.suit_id == 2:
            self.suit = "Hearts"
        elif self.suit_id == 3:
            self.suit = "Spades"
        elif self.suit_id == 4:
            self.suit = "Clubs"
        else:
            self.suit = "SuitError"

        self.short_name = self.rank[0] + self.suit[0]
        if self.rank == 10:
            self.short_name = self.rank + self.suit[0]
        self.long_name = self.rank + " of " + self.suit


deck = []
for suit_idt in range(1,5):
    for rank_idt in range(1,14):
        deck.append(Card(suit_idt,rank_idt))


hand = []
for cards in range(0,5):
    a = random.choice(deck)
    hand.append(a)
    deck.remove(a)

print
for card in hand:
    print card.short_name,=,card.long_name, "  Value:",card.value

 

随机生成一副扑克,布布扣,bubuko.com

随机生成一副扑克

标签:des   style   blog   color   for   art   div   ar   

原文地址:http://www.cnblogs.com/lfsblack/p/3873950.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!