当前位置: 首页>>代码示例>>Python>>正文


Python Card.__str__方法代码示例

本文整理汇总了Python中card.Card.__str__方法的典型用法代码示例。如果您正苦于以下问题:Python Card.__str__方法的具体用法?Python Card.__str__怎么用?Python Card.__str__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在card.Card的用法示例。


在下文中一共展示了Card.__str__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import __str__ [as 别名]
def main ():

     #Introduction
     print ("This program prints out n randomly generated playing cards. ")

     #Get input
     n = eval(input("\nHow many cards would you like? "))

     #Generate cards
     for i in range(n):
         rank = random.randrange(1, 13)
         suit = random.choice(["s", "h", "c", "d"])
         card = Card(rank, suit)
         print ()
         card.__str__()
         print ("The blackjack value of the card is", card.BJValue())
开发者ID:MichelleJaeg,项目名称:Exercises-from-Chapter-10,代码行数:18,代码来源:336.11.py

示例2: TestCard

# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import __str__ [as 别名]
class TestCard(unittest.TestCase):

    def setUp(self):
        self.twoOfClubs = Card(0)
        self.queenOfSpades = Card(43)

    def test_initialize(self):
        self.assertRaises(ValueError, Card, 52)

    def test_card_rank(self):
        self.assertEqual(self.twoOfClubs.rank(), "2")
        self.assertEqual(self.queenOfSpades.rank(), "Queen")

    def test_card_short_rank(self):
        self.assertEqual(self.twoOfClubs.short_rank(), "2")
        self.assertEqual(self.queenOfSpades.short_rank(), "Q")

    def test_card_suit(self):
        self.assertEqual(self.twoOfClubs.suit(), "Clubs")
        self.assertEqual(self.queenOfSpades.suit(), "Spades")
        
    def test_card_short_suit(self):
        self.assertEqual(self.twoOfClubs.short_suit(), "C")
        self.assertEqual(self.queenOfSpades.short_suit(), "S")
        
    def test_card_name(self):
        self.assertEqual(self.twoOfClubs.name(), "2 of Clubs")
        self.assertEqual(self.queenOfSpades.name(), "Queen of Spades")

    def test_card_short_name(self):
        self.assertEqual(self.twoOfClubs.short_name(), "2C")
        self.assertEqual(self.queenOfSpades.short_name(), "QS")
        
    def test_card_str(self):
        self.assertEqual(self.twoOfClubs.__str__(), "2 of Clubs")
        self.assertEqual(self.queenOfSpades.__str__(), "Queen of Spades")

    def test_card_repr(self):
        self.assertEqual(self.twoOfClubs.__repr__(), "<2C>")
        self.assertEqual(self.queenOfSpades.__repr__(), "<QS>")

    def test_card_comparison(self):
        self.assertTrue(self.twoOfClubs < self.queenOfSpades)
        queenOfHearts = Card(42)
        self.assertTrue(self.queenOfSpades == queenOfHearts)
开发者ID:FTWViolin,项目名称:summer_course,代码行数:47,代码来源:test_card.py

示例3: Card

# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import __str__ [as 别名]
from card import Card

card1 = Card(1, 1)
card2 = Card(3, 13)
card3 = Card(4, 13)
card4 = Card(3, 14)

print("card1, 1, 1 is: ", card1)
print("card2 3, 13 is: ", card2)
assert card1.__str__() == "Ace of Diamonds"
assert card2.__str__() == "King of Spades"
print("Pretty printing assertions Passed!!!")

assert card1.cmpSort(card2) == -1
assert card2.cmpSort(card1) == 1
assert card2.cmpSort(card2) == 0
print("cmpSort Assertions Passed!!!")

assert card1.cmp(card2) == -1
assert card2.cmp(card1) == 1
assert card2.cmp(card2) == 0
print("Cmp Assertions Passed!!!")

assert bool(card1.rank > card2.rank) == False
assert bool(card1.rank >= card2.rank) == False
assert bool(card1.rank < card2.rank) == True
assert bool(card1.rank <= card2.rank) == True
assert bool(card1.rank == card2.rank) == False
assert bool(card1.rank == card1.rank) == True
print("Comparison overloading assertions passed")
开发者ID:rvarley,项目名称:Blackjack,代码行数:32,代码来源:cardTests.py


注:本文中的card.Card.__str__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。