python中的卡片(类PlayCard& DeckOfCards)[已解决] [英] Cards in python (classes PlayingCard & DeckOfCards) [solved]

查看:113
本文介绍了python中的卡片(类PlayCard& DeckOfCards)[已解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在卡片类上工作,所以它可以做几件事。


我的代码和以前一样需要改变解决问题的事情


创建一个代表一副52张卡的新类Deck。该课程应该支持以下方法:

__init__(self)按标准顺序创建一副牌。

shuffle(self)随机化牌的顺序。 />
dealCard(self)从牌组顶部返回一张牌,并从牌组中移除牌。

cardsLeft(self)返回牌组中留下的牌数。

测试你的课程,让它处理一系列n卡片,其中n是用户输入的数字。该程序应打印出卡片,或在窗口中显示。


最后一个代码是: -


#card.py

导入字符串

n =输入("输入值:")

rank_desc =(无," Ace","两个,,三,四)#描述元组中的每个等级

suit_desc = {" s":" Spades"," h":" Hearts" ,c:俱乐部,d:钻石}#描述字典中的每件西装

类PlayCard:

def __init __( self,rank,suit):#创建一张卡片。

self.rank = rank

self.suit = suit

def __str __(self ):#返回命名卡的字符串。例如:''黑桃王牌''

返回%s的%s在二十一点中的价值%d %(rank_desc [self.rank],

suit_desc [self.suit],self.BJValue())

def getRank(self):#Returns the rank of the卡片。

返回self.rank

def getSuit(self):#返回卡片的套装。

返回self.suit

def BJValue(个体经营):#返回卡片的''Blackjack值''(Ace; 1,Face card:10)

返回min(self.rank,10)


AceOfSpades = PlayingCard(1,'s'')

打印AceOfSpades

打印AceOfSpades.getRank()


AceOfHearts = PlayingCard(2,''h'')

打印AceOfHearts
打印AceOfSpades.getRank()


AceOfClubs = PlayingCard(3,''c'')

打印AceOfClubs

打印AceOfSpades.getRank()


AceOfDiamonds = PlayingCard(4,''d'')

打印AceOfDiamonds

打印AceOfSpades.getRank()


我应该在此代码中更改哪些内容以解决上述问题?

i am worlking on the cards class so it can do several things.

My code is as before but need to change the things to solve given problem

Create a new class Deck that represents a pack of 52 cards. The class should support the following methods:
__init__ ( self ) Creates a deck of cards in standard order.
shuffle(self) Randomizes the order of the cards.
dealCard(self) Returns a single card from the top of the deck, and removes the card from the deck.
cardsLeft(self) Returns the number of cards left in the deck.
Test your class by having it deals out a sequence of n cards where n is a number input by the user. The program should either print out the cards, or display them in a window.

The last code was : -

#card.py
import string
n = input("Enter the value: ")
rank_desc = (None, "Ace", "Two", "Three", "Four") # describe each rank in a tuple
suit_desc = {"s":"Spades", "h":"Hearts", "c": "Clubs", "d": "Diamonds"} # describe each suit in a dictionary
class PlayingCard:
def __init__ ( self, rank, suit ): # Creates a card.
self.rank = rank
self.suit = suit
def __str__(self): # Returns a string naming the card. For example: ''Ace of Spades''
return "The %s of %s is worth %d in Blackjack" %(rank_desc[self.rank],
suit_desc[self.suit], self.BJValue())
def getRank(self): #Returns the rank of the card.
return self.rank
def getSuit(self): # Returns the suit of the card.
return self.suit
def BJValue(self): # Returns the ''Blackjack value'' of the card (Ace;1, Face card:10)
return min(self.rank, 10)

AceOfSpades = PlayingCard(1, ''s'')
print AceOfSpades
print AceOfSpades.getRank()

AceOfHearts = PlayingCard(2, ''h'')
print AceOfHearts
print AceOfSpades.getRank()

AceOfClubs = PlayingCard(3, ''c'')
print AceOfClubs
print AceOfSpades.getRank()

AceOfDiamonds = PlayingCard(4, ''d'')
print AceOfDiamonds
print AceOfSpades.getRank()

what should i change in this code to make it possible and solve out the above given problem?

推荐答案

请使用您发布的所有代码周围的[code] [/ code]标签重新发布消息。
Please repost your message using [code][/code] tags around all code you post.


展开 | 选择 | Wrap | 行号



i我在卡类上工作,所以它可以做几件事。


我的代码和以前一样需要改变要解决的问题


创建一个代表一副52张卡的新类Deck。该课程应该支持以下方法:

__init__(self)按标准顺序创建一副牌。

shuffle(self)随机化牌的顺序。 />
dealCard(self)从牌组顶部返回一张牌,并从牌组中移除牌。

cardsLeft(self)返回牌组中留下的牌数。

测试你的课程,让它处理一系列n卡片,其中n是用户输入的数字。该程序应该打印出卡片,或者在一个窗口中显示它们。


我应该在这段代码中改变什么来使它成为可能并解决上面给出的问题?
i am worlking on the cards class so it can do several things.

My code is as before but need to change the things to solve given problem

Create a new class Deck that represents a pack of 52 cards. The class should support the following methods:
__init__ ( self ) Creates a deck of cards in standard order.
shuffle(self) Randomizes the order of the cards.
dealCard(self) Returns a single card from the top of the deck, and removes the card from the deck.
cardsLeft(self) Returns the number of cards left in the deck.
Test your class by having it deals out a sequence of n cards where n is a number input by the user. The program should either print out the cards, or display them in a window.

what should i change in this code to make it possible and solve out the above given problem?



首先,改变你发布的方式(见下面和很多其他地方)。

其次,请从已经给你的作品(我们真的很想看你学习,不想认为我们正在为你做所有的工作)。

你将需要所有52张卡的规格给予:

First, change the way you post (see below and lots of other places).
Second, give this an honest attempt from the pieces that you have been given already (we really like to see you learning and don''t want to think that we are doing all your work for you).
You will need specifications for all 52 cards to give to the:

展开 | 选择 | Wrap | 行号


这篇关于python中的卡片(类PlayCard& DeckOfCards)[已解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆