Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So for a project, I decided to write a blackjack game in python 3. I have tried

ID: 3850223 • Letter: S

Question

So for a project, I decided to write a blackjack game in python 3. I have tried many different methods for getting my code to work, but all of them failed. I decided to take the best ideas from all of the code i've written and apply them to this blackjack game, but I can't decide how to move forward. Specifically, I've really been struggling with the value_setter function below. Can anyone take a look at my code and give me some advice?

from random import shuffle

RANK = [_ for _ in range(2, 11)] + ['Jack', 'Queen', 'King', 'Ace']
SUIT = ['Spades', 'Hearts', 'Diamonds', 'Clubs']


  

def deck_of_cards():
deck_of_cards = [[ranks, suits] for ranks in RANK for suits in SUIT]
shuffle(deck_of_cards)
return deck_of_cards

deck = deck_of_cards()   

def value_setter(card):

card[0] = RANK
if RANK in ranks[0:-4]:
count += int(rank)
elif RANK is 'Ace':
count += 11
elif RANK is 'Jack' or 'Queen' or 'King':
count += 10

return count

def initial_hands(deck):

player_hand = []
dealer_hand = []
while len(dealer_hand) < 2:
player_hand.append(deck[0])
deck.pop(0)
dealer_hand.append(deck[0])
deck.pop(0)

return [dealer_hand, player_hand]

Explanation / Answer

I think that the function you declared called value_setter(card) must look like this to function properly and with good execution time.There must a previous definition to the funtion so that it becomes easy to identify between the cards.

def name_of_card(self):
"""
Returns card names
"""
if self.position == 1:
Rank = "Ace"
elif self.position == 11:
Rank = "Jack"
elif self.position == 12:
Rank = "Queen"
elif self.position == 13:
Rank = "King"
else:
Rank = str(self.position)
return "{position} of {color}".format(position = Rank, color = self.color)

After declaring this function you will have your work done, I hope so.

Please rate the answer if it helped.....Thankyou

Hope it helps....

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote