Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Importing the random library in order for me to shuffle through the deck in order to get different suits and rank values
- import random
- #Declaring the variable suit as global before assigning any value to it
- global suit
- suit = ('Hearts', 'Diamonds', 'Spades', 'Clubs')
- #Declaring the variable rank as global before asssigning any value to it
- global rank
- rank = ('Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King', 'Ace')
- #Declaring the variable values as global before assigning any value to it
- global values
- values = {'Two': 2, 'Three': 3, 'Four': 4, 'Five': 5, 'Six': 6, 'Seven': 7, 'Eight': 8, 'Nine': 9, 'Ten': 10, 'Jack': 10, 'King': 10, 'Queen': 10, 'Ace': 11}
- #Declaring the variable counter if needed for a while loop or something
- global counter
- counter = 0
- #Declaring the boolean variable palying which will be needed for Gameplay
- playing = True
- '''
- Create a balck jac game main aim for the the class card is to take in on;y two attributes that is the suite and the rank
- Then display for example 'two of hearts' or '5 of Spades' etc etc
- '''
- class Card:
- #Declaring the __init__ whereby I take in two arguements as that is the suit and the rank which I declared as global
- def __init__(self, suit, rank):
- #Assigning self.suit amd self.rank to either one of the values that I g=have from the global variable suit and rank
- self.suit = suit
- self.rank = rank
- #Defining the __str__ so that I can display the rnak and the suit
- def __str__(self):
- return self.rank + " of " + self.suit
- #Definig the class Deck whereby I need to shuffle through them and display them....................
- class Deck:
- #Defining the __init__ whereby I inherite he values from the previous class using the self in the arguement __init__(self)
- def __init__(self):
- #Assigning self.deck to a empty list
- self.deck = []
- #Creating the for loop whereby I ittereate through the suit tuple that I created and suits will take in the value coming in from the suit
- for suits in suit:
- #Creating the for loop whereby I ittereate through the rank tuple that I created and ranks will take in the value coming in from the rank
- for ranks in rank:
- #Taking in the suit and rank and putting it in the list self.deck
- self.deck.append(Card(suit,rank))
- #Defining the __str__ method so that I display the deck that has been shuffled and taken into the self.deck
- def __str__(self):
- #Creating the for loop that will ittereate through the self.deck list that was created and assigned to card
- for card in self.deck:
- deck_comp = ''
- #Placing in the value of the card that was taken in from the self.deck so that I can display the deck_comp
- deck_comp += '\n' + card.__str__()
- return deck_comp
- #Defing the shuffle function so that it shuffles through the deck that I have to make it random
- def shuffle(self):
- random.shuffle(self.deck)
- #Defining the deal function that will take in the single_card
- #The single_card is the card that was taken in from the self.deck and
- def deal(self):
- single_card = self.deck.pop()
- return single_card
- test_deck = Deck()
- print(test_deck)
- '''
- Here is the error message thatg I get when I run the program can you please help me out I am honestly lost:
- Traceback (most recent call last):
- File "blackJack.py", line 95, in <module>
- print(test_deck)
- File "blackJack.py", line 74, in __str__
- deck_comp += '\n' + card.__str__()
- File "blackJack.py", line 40, in __str__
- return self.rank + " of " + self.suit
- TypeError: can only concatenate tuple (not "str") to tuple
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement