import random def getSuitName (suit): suitname = \"\" if (suit == \'d\'): suitna
ID: 3586560 • Letter: I
Question
import random
def getSuitName (suit):
suitname = ""
if (suit == 'd'):
suitname = "Diamonds"
elif (suit == 'h'):
suitname = "Hearts"
elif (suit == 'c'):
suitname = "Clubs"
else:
suitname = "Spades"
return suitname
def getRankName (rank):
rankname = ""
if (rank == 1):
rankname = "Ace"
elif (rank == 2):
rankname = "Two"
elif (rank == 3):
rankname = "Three"
elif (rank == 4):
rankname = "Four"
elif (rank == 5):
rankname = "Five"
elif (rank == 6):
rankname = "Six"
elif (rank == 7):
rankname = "Seven"
elif (rank == 8):
rankname = "Eight"
elif (rank == 9):
rankname = "Nine"
elif (rank == 10):
rankname = "Ten"
elif (rank == 11):
rankname = "Jack"
elif (rank == 12):
rankname = "Queen"
elif (rank == 13):
rankname = "King"
return rankname
class PlayingCard :
def __init__ (self, rank, suit):
self.rank = rank
self.suit = suit
self.suitname = getSuitName(self.suit)
self.rankname = getRankName(self.rank)
def getRank(self):
return self.rank
def getSuit(self):
return self.suit
def __str__ (self):
return self.rankname + " of " + self.suitname
def main():
suits = ("d", "h", "c", "s")
deck = []
for suit in suits:
for i in range (1, 13):
card = PlayingCard(i, suit)
deck.append(card)
for card in deck:
print(card)
random.shuffle(deck)
print(deck)
for card in deck:
print(card)
main()
In python
C https://miam.oh.instructure.com/courses/53369/assignments/529634#submit In the next assignment we are going to build a War card game People Chat WebEx We have a PlayingCard class, and we will need at least two other classes - a Deck class and a GUI class. (When you think about how War is played, you may want to consider another class in lieu of placing certain functionality in the GUI class, but that decision will be up to you.) Conferences For this part of the game, you will construct your Deck class. What is a Deck of cards? It is a collection of PlayingCards objects. In the PlayingCard class you were asked to test your class by creating a deck of cards. That functionality will need to be moved to a Deck class constructor Dashboard You will need to implement the following methods: Courses class Deck def_ init_ (self): initializes a list that represents a standard deck of cards that contains a set of PlayingCard objects calls the Deck shuffle method at least twice to shuffle the cards Groups Calendar def shuffle (self): shuffles the deck Inbox def getSize(self): Help returns the number of PlayingCards in the deck def deal (self): removes the top card in the deck and returns it security-graphic-1005 jpg Privacy PIA.jpg Module 6 Data Struct.pofModule 5 GUL Tkinter .pof Show AllExplanation / Answer
class Deck :
def shuffle(self):
random.shuffle(self.deck_list)
def __init__(self,playing_card_list):
self.deck_list=playing_card_list
self.shuffle()
self.shuffle()
def getSize(self):
return len(self.deck_list)
def deal(self):
removed_card=self.deck_list.pop(0)
return removed_card
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.