Untitled
unknown
plain_text
2 years ago
1.9 kB
5
Indexable
from art import logo import random def hands_showing(): print(f"Your cards: {players_hand}, current score: {sum(players_hand)}") print(f"Computer's first card: {dealers_hand[0]} ") def next_card(): players_hand.append(random.choice(cards)) if sum(dealers_hand) < 21: dealers_hand.append(random.choice(cards)) def final_hand(): print(f"Your final hand: {players_hand}, final score {sum(players_hand)}") print(f"Computer's final hand: {dealers_hand}, final score {sum(dealers_hand)}") cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10] players_hand = [] dealers_hand = [] #dealing first two cards: for card in range(2): players_hand.append(random.choice(cards)) dealers_hand.append(random.choice(cards)) hands_showing() if sum(players_hand) == 21: print("You got a blackjack! You won!") elif sum(dealers_hand) == 21: print("Computer got a blackjack! You lose!") else: continue_dealing = True while continue_dealing: new_card = input("Type 'y' to get another card, type 'n' to pass: ") if new_card == "y": next_card() if sum(players_hand) > 21: final_hand() print("You went over. You lose 😭") break elif sum(players_hand) == 21: final_hand() print("You win 😃") break else: hands_showing() elif new_card == "n": if sum(dealers_hand) < sum(players_hand) or sum(dealers_hand) == sum(players_hand): dealers_hand.append(random.choice(cards)) if sum(dealers_hand) > 21 and sum(dealers_hand) > sum(players_hand): final_hand() print("Opponent went over. You win 😁") break if sum(dealers_hand) < 21 and sum(dealers_hand) > sum(players_hand): final_hand() print("You lose 😤") break
Editor is loading...