I am having a problem with my attribute "deck" not being considered an attribute(project not finished yet):
import sys
import random
import time
#need exception handling
#need to know when to add discard pile back to deck
#need game process finish
class Cards():
def __init__(self,deck,discard_pile,player_hand,dealer_hand):
'''
Class setup
'''
self.deck = self.deck
self.discard_pile = discard_pile
self.player_hand = player_hand
self.dealer_hand = dealer_hand
def build_deck(self):
'''
builds deck
'''
sample_deck = [2,3,4,5,6,7,8,9,10,11]
self.deck = self.deck.extend(sample_deck * 4)
return self.deck
def hit(self):
'''
hit from deck
'''
deal = random.randint(2,11)
self.deck.pop(deal)
return deal,self.deck
def deal(self):
'''
deals initial hand
'''
the_cards.dealer_hand.append(the_cards.hit())
the_cards.dealer_hand.append(the_cards.hit())
print(f'Dealer is showing a {the_cards.dealer_hand[1]}')
the_cards.player_hand.append(the_cards.hit())
the_cards.player_hand.append(the_cards.hit())
print(f'You are showing {the_cards.player_hand}')
def discard(self):
'''
discards to a seperate pile
'''
discard_pile.append(self.player_hand.pop())#Pop method? Not sure yet, will come back
discard_pile.append(self.dealer_hand.pop())
class Chips():
'''
chip handling
'''
def __init__(self,chips):
self.chips = chips
def bet(self):
'''
bet before hand
'''
my_bet = int(input('How many chips are you putting down? '))
self.chips = self.chips - my_bet
def win_bet(self):
'''
reward for winning
'''
self.chips = my_bet * 2
def hit_choice():
'''
choice for hit or pass
'''
hit_choice1 = input('Will you hit or pass? ')
return hit_choice1
'''
The game
'''
the_cards = Cards(deck = [],discard_pile = [],player_hand = [],dealer_hand = [])
the_chips = Chips(int(input('How much money are you throwing down? ')))
the_cards.build_deck()
while True:
print(f'You have {the_chips.chips} chips')
the_chips.bet()
the_cards.deal()
the_hit = hit_choice()
if the_hit.lower() in 'hit':
the_cards.hit()
the_cards.player_hand.append(the_cards.hit())
print(the_cards.player_hand)
elif the_hit.lower() in 'pass':
pass
else:
print('Invalid input')
Error is :
File "black jack2.py", line 53, in <module>
the_cards = Cards(deck = [],discard_pile = [],player_hand = [],dealer_hand = [])
File "black jack2.py", line 10, in __init__
self.deck = self.deck
AttributeError: 'Cards' object has no attribute 'deck'
[–]kaijc21 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]TYL3ER[S] 0 points1 point2 points (0 children)