Python Code Self Learn
Python Code Self Learn
BlackJack Art:
logo = """
.------. _ _ _ _ _
|A_ _ |. || || | | (_) ||
| \/ K| _/ |
`------' |__/
"""
import random
def deal_card():
card = random.choice(cards)
return card
def calculate_score(cards):
"""Take a list of cards and return the score calculated from the cards"""
cards.remove(11)
cards.append(1)
return sum(cards)
# Bug fix. If you and the computer are both over, you lose.
if user_score == computer_score:
elif computer_score == 0:
elif user_score == 0:
else:
def play_game():
print(logo)
user_cards = []
computer_cards = []
is_game_over = False
for _ in range(2):
user_cards.append(deal_card())
computer_cards.append(deal_card())
user_score = calculate_score(user_cards)
computer_score = calculate_score(computer_cards)
is_game_over = True
else:
user_should_deal = input("Type 'y' to get another card, type 'n' to pass: ")
if user_should_deal == "y":
user_cards.append(deal_card())
else:
is_game_over = True
computer_cards.append(deal_card())
computer_score = calculate_score(computer_cards)
while input("Do you want to play a game of Blackjack? Type 'y' or 'n': ") == "y":
play_game()