самообучение Python. Это простая игра в блэкджек, над которой я работал через онлайн-видео-инструкцию. Игра проходит достаточно хорошо, но я не могу обновить свои выигрыши или проигрыши обратно в банк после игры. У меня есть ощущение, что это может иметь какое-то отношение к clear_output (), который я использую после функции приема ставок. Что я делаю неправильно? Во-первых, мой класс фишек здесь.
class Chips:
def __init__(self):
self.total = 100
self.bet = 0
def win_bet(self):
self.total += self.bet
def lose_bet(self):
self.total -= self.bet
Затем я go в определение функций
def player_busts(player,dealer,chips):
print("You busted. Too bad.")
chips.lose_bet()
def player_wins(player,dealer,chips):
print("You win!")
chips.win_bet()
def dealer_busts(player,dealer,chips):
print("Dealer busts!")
chips.win_bet()
def dealer_wins(player,dealer,chips):
print("Dealer wins!")
chips.lose_bet()
def take_bet(chips):
clear_output()
print('Welcome to Adams BlackJack!')
print('Get as close to 21 as you can without going over!')
print('You have '+str(chips.total)+' chips.')
while True:
try:
chips.bet = int(input('How much would you like to bet, hotshot? '))
except ValueError:
print('Sorry, your bet must be an integer!')
else:
if chips.bet > chips.total:
print("Sorry, you don't have that much money.",chips.total)
else:
break
Затем я go в фактический код, который запускает игру.
playing = True
while True:
deck = Deck()
deck.shuffle()
player_hand = Hand()
player_hand.add_card(deck.deal())
player_hand.add_card(deck.deal())
dealer_hand = Hand()
dealer_hand.add_card(deck.deal())
dealer_hand.add_card(deck.deal())
player_chips = Chips()
print("\nYour chips: ",player_chips.total)
take_bet(player_chips)
show_some(player_hand,dealer_hand)
while playing:
hit_or_stand(deck,player_hand)
show_some(player_hand,dealer_hand)
if player_hand.value > 21:
player_busts(player_hand,dealer_hand,player_chips)
break
if player_hand.value <= 21:
while dealer_hand.value < 17:
hit(deck,dealer_hand)
show_all(player_hand,dealer_hand)
if dealer_hand.value > 21:
dealer_busts(player_hand,dealer_hand,player_chips)
elif dealer_hand.value > player_hand.value:
dealer_wins(player_hand,dealer_hand,player_chips)
elif dealer_hand.value < player_hand.value:
player_wins(player_hand,dealer_hand,player_chips)
else:
push(player_hand,dealer_hand)
print("\nYour chips: ",player_chips.total)
new_game = input("Would you like to play another hand? Enter 'y' or 'n' ")
if new_game[0].lower()=='y':
playing=True
continue
else:
print("Thanks for playing! bye now, mmkay?")
break
Можно ли добавить в мое утверждение if строку, в которой мои выигрыши добавляются к моим общим фишкам?