python For this part you can choose to write a playable game

python

For this part you can choose to write a playable game of Blackjack for extra credit. In Blackjack the players is dealt a series of cards that have an associated point value. The goal is to collect a hand of cards that comes as close to 21 points as possible without going over 21 In a Blackjack deck of cards every card has an associated value. All of the possible cards and the corresponding values can be found in the following lists. Note that the card at position 0 (10 of hearts) has its point value at position 0 in the second list: cards [\'10 of Hearts \'9 of Hearts\', \'8 of Hearts\', \'7 of Hearts \'6 of Hearts 5 of Hearts\', \'4 of Hearts\', \'3 of Hearts\', 2 of Hearts Ace of Hearts King of Hearts Queen of Hearts Jack of Hearts 10 of Diamonds 9 of Diamonds 8 of Diamonds 7 of Diamonds 6 of Diamonds 5 of Diamonds 4 of Diamonds 3 of Diamonds 2 of Diamonds Ace of Diamonds King of Diamonds Queen of Diamonds Jack of Diamonds i 10 of Clubs 9 of Clubs 8 of Clubs 7 of Clubs 6 of Clubs 5 of Clubs 4 of Clubs 3 of Clubs 2 of Clubs Ace of Clubs King of Clubs Queen of Clubs Jack of Clubs 10 of Spades 9 of Spades 8 of Spades 7 of Spades 6 of Spades 5 of Spades 4 of Spades 3 of Spades 2 of Spades Ace of Spades King of Spades Queen of Spades Jack of Spades values 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 10, 101

Solution

# filename: BlackJack.py

#I have corrected some printing mistake and other things please use this updated file

from random import randint

  
def start_game():
print(\"game is Starting\")
c1,c2 = get_randome_two_card()
  
player_card.append(cards[c1])
player_card.append(cards[c2])
del cards[c1]
del cards[c2]
score = get_score(player_card)
print_card(\"You\",player_card,score)
next_move =\"\"
while True:
global message
global player
next_move = input(\"(h)it or(s)tand?\")
if next_move==\"h\":
index =randint(0,len(cards)-1)
new_card = cards[index]
player_card.append(new_card)
print(\"you Drew \",new_card)
del cards[index]
score = get_score(player_card)
print_card(\"you\",player_card,score)
result =check_reslut(score)
if result==-1:
if len(cards)==0:
break
continue
elif result==1:
message=1
player=\"You\"
break
else:
message=0
break
elif next_move==\"s\":
get_computer_move(cards)
break

def get_computer_move(cards):
global message
global player
c1,c2 = get_randome_two_card()
  
computer_player_card.append(cards[c1])
computer_player_card.append(cards[c2])
del cards[c1]
del cards[c2]
score = get_score(computer_player_card)
print_card(\"Computer\",computer_player_card,score)
while True:
print(\"(h)it or(s)tand?h\")
index =randint(0,len(cards)-1)
new_card = cards[index]
computer_player_card.append(new_card)
print(\"Computer Drew \",new_card)
print()
del cards[index]
score = get_score(computer_player_card)
print_card(\"Computer\",computer_player_card,score)
result =check_reslut(score)
if result==-1:
if len(cards)==0:
break
else:
continue
elif result==1:
message=1
player=\"Computer\"
break
else:
message=0
print(\"Bust!\")
print(\"You Wins!\")
break
  
def print_card(player,player_card,score):
print(player,\" hand\",player_card,\"is worth\",score)

  
  
  
  
def get_score(players_card):
return sum([search_deck[x] for x in player_card])

  
def get_randome_two_card():
return (randint(0,51),randint(0,51))

def check_reslut(score):   
if score > 21:
return 0
elif score==21:
return 1
else:
return -1


if __name__ == \"__main__\":
suits=[\"Hearts\",\"Clubs\",\"Diamonds\",\"Spades\"]
face_cards =[\"Ace\",\"Jack\",\"Queen\",\"King\"]
sequence = list(range(2,11))+face_cards
cards_with_value = [ (str(y)+\" of \"+x,10 if y in face_cards and y!=\'Ace\' else 1 if y in face_cards and y==\'Ace\' else y ) for x in suits for y in sequence]
cards = [x[0] for x in cards_with_value]   
values = [x[1] for x in cards_with_value]
search_deck = dict(cards_with_value)   
player_card =[]
computer_player_card =[]
message=-1
player =\"\"
start_game()
if message==1 and player==\"You\":
print(\"You Wins!\")
elif message==1 and player==\"Computer\":
print(\"Bust\")
print(\"Computer Wins!\")
elif message==-1:
player_score = get_score(player_card)
computer_score = get_score(computer_player_card)
if player_score>computer_score:
print(\"you win\")
else:
print(\"Bust\")
print(\"Computer Wins!\")
  
  

python For this part you can choose to write a playable game of Blackjack for extra credit. In Blackjack the players is dealt a series of cards that have an ass
python For this part you can choose to write a playable game of Blackjack for extra credit. In Blackjack the players is dealt a series of cards that have an ass
python For this part you can choose to write a playable game of Blackjack for extra credit. In Blackjack the players is dealt a series of cards that have an ass

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site