Untitled
unknown
python
3 years ago
3.0 kB
7
Indexable
import random
from blackjack_logo import logo
def deal_card():
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
return random.choice(cards)
def users_starting_hand():
users_cards = [deal_card(), deal_card()]
return users_cards
def computers_starting_hand():
return deal_card()
def wanna_continue():
users_decision = input("Type 'y' to get another card, type 'n' to pass: ")
return users_decision
def blackjack():
wanna_play = input("Do you want to play a game of Blackjack? Type 'y' or 'n': ")
if wanna_play == 'y':
print(logo)
users_cards = users_starting_hand()
users_current_score = sum(users_cards)
computers_card = computers_starting_hand()
print(f"Your cards: {users_cards}, current score: {users_current_score}")
print(f"Computer's first card: {computers_card}")
computers_cards = [computers_card, deal_card()]
computers_current_score = sum(computers_cards)
if computers_current_score == 21:
print("Sorry, you lose!")
elif users_current_score == 21:
print("You win!")
exit()
if users_current_score > 21:
ace = 11
if ace not in users_cards:
print("You lose!")
else:
if ace in users_cards:
ace = 1
if sum(users_cards) > 21:
print("You lose!")
else:
wanna_continue()
if wanna_continue() == 'y':
users_cards.append(deal_card())
users_current_score = sum(users_cards)
blackjack()
elif wanna_continue() == 'n':
computers_cards.append(deal_card())
computers_current_score = sum(computers_cards)
if computers_current_score < 17:
computers_cards.append(deal_card())
computers_current_score = sum(computers_cards)
if computers_current_score > 21:
print("You win!")
else:
if users_current_score == computers_current_score:
print("Draw!")
elif users_current_score > computers_current_score:
print("You win!")
elif computers_current_score > users_current_score:
print("You lose!")
elif users_current_score < 21:
wanna_continue()
if wanna_continue() == 'y':
users_cards.append(deal_card())
users_current_score = sum(users_cards)
elif wanna_play == 'n':
exit()
blackjack()Editor is loading...