本文整理汇总了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())
示例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)
示例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")