Question: can anyone tell me why I'm getting this error ? In addition to an _init__method we'll want to add methods to shuffle our deck, and

can anyone tell me why I'm getting this error ?  can anyone tell me why I'm getting this error ? In
addition to an _init__method we'll want to add methods to shuffle our
deck, and to deal out cards during gameplay OPTIONAL: We may never
need to print the contents of the deck during gameplay, but having

In addition to an _init__method we'll want to add methods to shuffle our deck, and to deal out cards during gameplay OPTIONAL: We may never need to print the contents of the deck during gameplay, but having the ability to see the cards inside it may help troubleshoot any problems that occur during development. With this in mind, consider adding a _str_ method to the class definition [49]: class Deck: def definit__(self): self.deck - [] # start with an empty list for suit in suits: for rank in ranks: self.deck.append(Card(suit, rank)) # build Card objects and add str_(self): deck_comp # start with an empty string for card in self.deck: deck_comp + ' '+card._str_() # add each Card object's print str return 'The deck has:' + deck_comp def shuffle(self): random.shuffle(self.deck) def deal(self): single_card self.deck.pop() return single_card TESTING: Just to see that everything works so far, let's see what our Deck looks like! In [50]: test_deck Deck() print(test_deck) jupyter 02-Milestone Project 2 - Walkthrough Steps Workb... (autonaven) File Edit View Insert Cell Kemel Widgets Help Trusted 361 Run Markdown def shuffle(self): random.shuffle(self.deck) def deal(self): single_card - self.deck.pop() return single_card TESTING: Just to see that everything works so far let's see what our Deck looks like! In [50]: test_deck - Deck() print(test_deck) in 1 test_deck - Deck ---> 2 print(test_deck) in_str_(self) le deck_comp = # start with an empty string 11 for card in self.deck: ---> 12 deck_comp - 'In card._str_0 # add each card objec t's print string 13 return "The deck has: + deck_comp 14 in str (self) 6 7 def str_(self): ----> 8 return self.rank" of "self.suit AttributeError: Card' object has no attribute 'suit Great Now let's move on to our Hand class Step 4: Create a Hand Class In addition to holding Card objects dealt from the Deck the Hand class may be used to calculate the value of those cards using the values dictionary defined above it may also need to adjust for the value of Aces when appropriate In [51] class Hand: def int(self): solf cards 29/0 jupyter 02-Milestone Project 2 - Walkthrough Steps Workb... (autonaven) File Edit View Insert Cell Kemel Widgets Help Trusted 361 Run Markdown def shuffle(self): random.shuffle(self.deck) def deal(self): single_card - self.deck.pop() return single_card TESTING: Just to see that everything works so far let's see what our Deck looks like! In [50]: test_deck - Deck() print(test_deck) in 1 test_deck - Deck ---> 2 print(test_deck) in_str_(self) le deck_comp = # start with an empty string 11 for card in self.deck: ---> 12 deck_comp - 'In card._str_0 # add each card objec t's print string 13 return "The deck has: + deck_comp 14 in str (self) 6 7 def str_(self): ----> 8 return self.rank" of "self.suit AttributeError: Card' object has no attribute 'suit Great Now let's move on to our Hand class Step 4: Create a Hand Class In addition to holding Card objects dealt from the Deck the Hand class may be used to calculate the value of those cards using the values dictionary defined above it may also need to adjust for the value of Aces when appropriate In [51] class Hand: def int(self): solf cards 29/0 Class Definitions Consider making a Card class where each Card object has a suit and a rank, then a Deck class to hold all 52 Card objects, and can be shuffled, and finally a Hand class that holds those Cards that have been dealt to each player from the Deck Step 2: Create a Card Class A Card object really only needs two attributes: suit and rank. You might add an attribute for "value" - We chose to handle value later when developing our Hand class. In addition to the Card's _init_method, consider adding a __str__method that, when asked to print a Card, returns a string in the form "Two of Hearts" [48]: def init__(self, suit, rank) self.suit - suit self.rank - rank def__str_(self): return self.rank. of self.suit Step 3: Create a Deck Class Here we might store 52 card objects in a list that can later be shuffled First, though, we need to instantiate all 52 unique card objects and add them to our list. So long as the card class definition appears in our code, we can build Card objects inside our Deck_init_method Consider iterating over sequences of suits and ranks to build out each card. This might appear inside a Deck class method for suit in suits: for rank in ranks: In addition to an __init_method we'll want to add methods to shuffle our deck, and to deal out cards during gameplay OPTIONAL We may never need to print the contents of the deck during gameplay, but having the ability to see the cards inside it may help troubleshoot any problems that occur during development within mind, consider adding a Str method to the class definition in (aoy: class beck: T2 29/01/2027

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!