# Blackjack

What’s up guys,

I have recently finished my first personal project, a game of blackjack. I would like to see some feedback from you guys, maybe tell me what I could’ve done easier or better and or something I should add to the code.

Note that I chose so the dealer would fold if the sum of his hand is bigger or equal to 17.

Kind regards,

Aron

``````from random import randint
import sys

pack = {m:4 for m in range(1, 14)}
pack[0] = 0
player_name = input("Hello, today we will be playing BlackJack. My name is Aron, I am the dealer. What is your name?")
print("Nice to meet you {}, let's get started.".format(player_name))

dealer = []
player = []
def calculate_sum(who):
sum = 0
for m in who:
if m >= 10:
sum += 10
else:
sum += m
return sum

def message(who, x):
if x == "The dealer":
print("{}, drew {} the sum of his hand is now {}.".format(x, who[-1], calculate_sum(who)))
else:
print("{}, drew {} the sum of your hand is now {}.".format(x, who[-1], calculate_sum(who)))

def card_draw(who):
draw = 0
while pack[draw] < 1:
draw = randint(1, 13)
if pack[draw] > 0:
pack[draw] -= 1
break
return who.append(draw)

card_draw(dealer)
message(dealer, "The dealer")

card_draw(player)
message(player, "You")
next = "Y"
while next.lower() == "y":
card_draw(player)
message(player, "You")
if calculate_sum(player) > 21:
sys.exit("You have exceeded 21, you loose!")
next = input("Whould you like to continue? Y/N")

while calculate_sum(dealer) < 17:
card_draw(dealer)
if calculate_sum(dealer) > 21:
sys.exit("The dealer drew for a total of {}, you win!".format(calculate_sum(dealer)))
print(calculate_sum(dealer))

if calculate_sum(dealer) > calculate_sum(player):
print("The dealer has a score of {} while you have a score of {}. The dealer wins.".format(calculate_sum(dealer), calculate_sum(player)))
elif calculate_sum(dealer) < calculate_sum(player):
print("The dealer has a score of {} while you have a score of {}. You win.".format(calculate_sum(dealer),calculate_sum(player)))
elif calculate_sum(dealer) == calculate_sum(player):
print("It's a draw!")

``````