Question: PYTHON BLACKJACK HELP: The main method is required but it is causing a lot of issues with my code, how can I make it work?

PYTHON BLACKJACK HELP: The main method is required but it is causing a lot of issues with my code, how can I make it work?

Prompt (the main method is the starter code)

PYTHON BLACKJACK HELP: The main method is required but it is causinga lot of issues with my code, how can I make it

Current Code

#!/usr/bin/env python3

import random

CARDS_CHARACTERS = {"Spades": "", "Hearts": "", "Diamonds": "", "Clubs": ""}

class Card:

def __init__(self, suit, rank,value):

self.suit = CARDS_CHARACTERS

self.rank = {"Ace","2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}

self.__value = value

@property

def value(self):

return self.__value

@value.setter

def value(self,value):

value = 0

has_ace = False

for card in self.cards:

if card.value.isnumeric():

self.value += int(card.value)

else:

if card.value == "A":

has_ace = True

self.value += 11

else:

self.value += 10

self.__value = value

def displayCard(self):

return (self.rank + " of "+ self.suit)

class Deck(Card):

def __init__(self, suit ="", rank="",value = 0):

Card.__init__(self, suit, rank,value)

self.__count = count

self.__deck = deck2

@property

def deck2(self):

return self.__deck

@deck2.setter

def deck2(self,deck1):

deck1 = []

for suit in range(4):

for rank in range(1, 14):

self.__deck.append(Card(suit, rank))

self.__deck = deck1

return deck1

@property

def count(self):

self.count = len(self.__deck)

return self.__count

@deck2.setter

def count(self,counting):

counting = len(self.__deck)

counting = count

class Hand(Card):

def __init__(self, suit, rank,cards2 = []):

Card.__init__(self, suit, rank)

self.__count2 = count2

self.cards2 = cards2

@property

def count2(self):

self.count2 = len(self.cards2)

return self.count2

def add_card(self):

self.cards2.append(Card)

def displayHand(self):

x = Card.displayCard(self)

for x in range(self.cards2):

print(x)

def main():

print("Cards - Tester")

print()

print("DECK")

deck = Deck()

print("Deck created.")

Deck.shuffle()

print("Deck shuffled.")

print("Deck count:", deck.count)

print()

# test hand

print("HAND")

hand = Hand()

for i in range(4):

hand.addCard(deck.dealCard())

hand.displayHand()

print()

print("Hand points:", hand.points)

print("Hand count:", hand.count)

print("Deck count:", deck.count)

if __name__ == "__main__":

main()

Course Project Phase 1 This is the first phase of 3 phase project we will be doing in this course. The project is to build a card game. The game is a simplified version of the Blackjack game. We will be building this in three steps, each of which will hopefully be easy to understand and implement. In the first phase of the project, you will create classes required to play any card game. Specifically, download the objects.py file that is provided. It has test-code in the main() method. You should define the three classes listed below in this file, uncomment the test code and run it. See sample runs below. 1. Create a Card class: Class to represent a playing card with the following requirements: a. Attributes: 1. suit: a public attribute representing suit of the card. Possible values: "Spades", "Hearts", "Diamonds" and "Clubs" ii. rank: a public attribute representing rank of the card. Possible values: "Ace", "2", "3", "4", "5", "6","7","8","9", "10", "Jack", "Queen", "King". b. Properties: 1. value: A public read-only property that represents the point value of the card. It is only dependent on the rank of the card: An Ace is worth 11 points, Jack/Queen/King each is 10 points and the rest of the cards worth their rank value. E.g. Deuce (a "2") is worth 2 points, a "3" is worth 3 points, etc. Hint: You can use the int function to convert the rank of the non-face cards to the corresponding point value. C. A constructor: 1. This takes two required arguments: first one is rank and second one is suit and initializes the corresponding public attributes. For consistency, make sure the order of the arguments is maintained - first one is the rank and the second one is the suit. So Card("King", "Hearts") will create a card object representing "King of Hearts" and Card("7", "Spodes") will create a card object representing "7 of Spades". d. Methods 1. displayCard: a method that takes no parameters and returns a string of the form "rank of suit suitsymbol". E.g. "King of Hearts", "10 of Diamonds", or "3 of Clubs " Hint: For your convenience a dictionary is provided at the top of the object.py file that has these symbols corresponding to each sult. Use this dictionary here. 2. Create a Deck class: Class to represent a deck of cards that is used to play a card game. This class has the following requirements: a. Attributes: 1. _deck: a private attribute which is a list of objects of Card class. b. Properties: 1. count: A read-only property equal to the count of cards currently in the _deck list. c. A constructor 1. This takes no arguments. It initializes _deck attribute with 52 objects of Card class with one of each card type. That's 13 with suit = "Spades" and ranks from "2" to "Ace", 13 with suit = "Hearts" and ranks from "2" to "Ace", and so on, so that_deck has all unique 52 cards. These can be in a perfect order. There are many ways to fill in this list of 52, using loop constructs. Hint: One possible way is to use two lists one initialized to 4 possible values of suit and other initialized to 13 possible values of rank. Then use a nested loop to loop over these two creating all possible pairings of suit and rank to create the 52 cards. But feel free to use any other way to use loops here. d. Methods 1. shuffle: a method with no arguments that shuffles the deck to a random order. Hint: Use the shuffle method of the random module that takes a list and shuffles in place. il. dealCard: a method with no arguments that removes a card from the deck and returns it. 3. Create a Hand class: Class to represent the dealer's hand or the player's hand. This class has the following requirements: a. Attributes: i. _cards: a private attribute which is a list of objects of Card class. b. Properties: 1. count: A read-only property equal to the count of cards currently in the _cards list. ii. points: A read-only property equal to total points of the cards in the hand. c. A constructor: This takes no arguments. It initializes __cards attribute to an empty list. d. Methods: 1.addCard: a method that takes one argument of Card class object and appends it to the _cards list. ii. displayHand: a method with no arguments that prints the hand by printing the strings returned by displayCard method of each of the cards in the _cards list. Add these class definitions to the objects.py file, uncomment the test code and run it. See the samples runs below. Submit the file with a name of the form first_last_objects.py. Be sure to add the title comment-block at the top of the file giving details such as your name, class name, date etc

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!