Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.81 KB | None | 0 0
  1. #Importing the random library in order for me to shuffle through the deck in order to get different suits and rank values
  2. import random
  3.  
  4. #Declaring the variable suit as global before assigning any value to it
  5. global suit
  6. suit = ('Hearts', 'Diamonds', 'Spades', 'Clubs')
  7.  
  8. #Declaring the variable rank as global before asssigning any value to it
  9. global rank
  10. rank = ('Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King', 'Ace')
  11.  
  12. #Declaring the variable values as global before assigning any value to it
  13. global values
  14. 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}
  15.  
  16. #Declaring the variable counter if needed for a while loop or something
  17. global counter
  18. counter = 0
  19.  
  20. #Declaring the boolean variable palying which will be needed for Gameplay
  21. playing = True
  22.  
  23. '''
  24. 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
  25.  
  26. Then display for example 'two of hearts' or '5 of Spades' etc etc
  27.  
  28. '''
  29. class Card:
  30.  
  31.     #Declaring the __init__  whereby I take in two arguements as that is the suit and the rank which I declared as global
  32.     def __init__(self, suit, rank):
  33.  
  34.         #Assigning self.suit amd self.rank to either one of the values that I g=have from the global variable suit and rank
  35.         self.suit = suit
  36.         self.rank = rank
  37.  
  38.     #Defining the __str__ so that I can display the rnak and the suit
  39.     def __str__(self):
  40.         return self.rank + " of " + self.suit
  41.  
  42.  
  43.  
  44. #Definig the class Deck whereby I need to shuffle through them and display them....................
  45. class Deck:
  46.  
  47.     #Defining the __init__ whereby I inherite he values from the previous class using the self in the arguement __init__(self)
  48.     def __init__(self):
  49.  
  50.         #Assigning self.deck to a empty list
  51.         self.deck = []
  52.  
  53.         #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
  54.         for suits in suit:
  55.  
  56.             #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
  57.  
  58.             for ranks in rank:
  59.  
  60.                 #Taking in the suit and rank and putting it in the list self.deck
  61.                 self.deck.append(Card(suit,rank))
  62.  
  63.  
  64.     #Defining the __str__ method so that I display the deck that has been shuffled and taken into the self.deck
  65.     def __str__(self):
  66.  
  67.  
  68.  
  69.         #Creating the for loop that will ittereate through the self.deck list that was created and assigned to card
  70.         for card in self.deck:
  71.  
  72.             deck_comp = ''
  73.             #Placing in the value of the card that was taken in from the self.deck so that I can display the deck_comp
  74.             deck_comp += '\n' + card.__str__()
  75.  
  76.  
  77.         return deck_comp
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.     #Defing the shuffle function so that it shuffles through the deck that I have to make it random
  85.     def shuffle(self):
  86.         random.shuffle(self.deck)
  87.  
  88.     #Defining the deal function that will take in the single_card
  89.     #The single_card is the card that was taken in from the self.deck and
  90.     def deal(self):
  91.         single_card = self.deck.pop()
  92.         return single_card
  93.  
  94. test_deck = Deck()
  95. print(test_deck)
  96.  
  97. '''
  98. Here is the error message thatg I get when I run the program can you please help me out I am honestly lost:
  99.  
  100. Traceback (most recent call last):
  101.  File "blackJack.py", line 95, in <module>
  102.    print(test_deck)
  103.  File "blackJack.py", line 74, in __str__
  104.    deck_comp += '\n' + card.__str__()
  105.  File "blackJack.py", line 40, in __str__
  106.    return self.rank + " of " + self.suit
  107. TypeError: can only concatenate tuple (not "str") to tuple
  108. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement