Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

issue where I get syntax error 'return outside the function' elif Mode == 2: def dealCard(turn): card = random.choice(Deck) turn.append(card) Deck.remove(card) def total(hand): total =

issue where I get syntax error 'return outside the function'

elif Mode == "2": def dealCard(turn): card = random.choice(Deck) turn.append(card) Deck.remove(card) def total(hand): total = 0 ace_11s = 0 for card in hand: if card in range(11): total += card elif card in ["J", "K", "Q"]: total += 10 else: total += 11 ace_11s += 1 while ace_11s and total > 21: total -= 10 ace_11s -= 1 return total def revealdealerhand(): if len(dealerhand) == 2: return dealerhand [0] elif len(dealerhand) > 2: return dealerhand[0], dealerhand[1] print("We will play multiplayer") num_players = int(input("How many players? (up to 3): ")) player_hands = [[] for _ in range(num_players)] highest_total = 0 winner_index = -1 for i in range(num_players): for j in range (2): dealCard(player_hands[i]) for j in range(2): dealCard(dealerhand) for i in range(num_players): player_st = True while player_st: print(f"Dealer has {revealdealerhand()} and X") for j in range(num_players): print(f"Player {j + 1} has {player_hands[j]} for total of {total(player_hands[j])}") stayOrHit = input(f"Player {i + 1}: S: Stay H: Hit ") if stayOrHit == "S": player_st = False else: dealCard(player_hands[i]) for i in range(num_players): player_total = total(player_hands[i]) if player_total > highest_total and player_total <= 21: highest_total = player_total winner_index = i dealer_total = total(dealerhand) if dealer_total > highest_total and dealer_total <= 21: highest_total = dealer_total winner_index = num_players if winner_index == -1: print("Everyone busts! there's no winner.") elif winner_index == num_players: print("The dealer wins!") else: print(f"Player {winner_index + 1} wins!") for i in range(num_players): player_total = total(player_hands[i]) if player_total == 21 and len(player_hands[i]) == 2: print(f"Player {i + 1} has Blackjack! They win!") return dealer_total = total(dealerhand) if dealer_total == 21 and len(dealerhand) == 2: print("The dealer has blackjack! They win!") return for i in range(num_players): player_total = total(player_hands[i]) if player_total == highest_total and player_total == dealer_total: print(f"Player {i + 1} ties with the dealer!")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Understand what a service-oriented culture is.

Answered: 1 week ago

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago