改善のよちがあったらお願いします。```
よろしくお願いします。
python
1import random 2 3# Ask player bet or not 4bet = False 5bet = str(input("Do you want to play Blackjack? Type yes or no >> ")).lower() 6if bet == "yes": 7 bet = True 8elif bet == "": 9 bet = True 10else: 11 12 exit() 13 14while bet: 15 # place your bet(up to 10,000$) 16 player_bet = input("Enter your bet (Max 10000$): ") 17 if int(player_bet) > 10000: 18 player_bet = input("Maximun bet is 10000$: ") 19 elif int(player_bet) <= 0: 20 player_bet = input("Minimun bet is 1$: ") 21 22 # Dealer cards 23 dealer_cards = [] 24 # Players cards 25 player_cards = [] 26 27 # Deal the cards 28 while len(dealer_cards) != 2: 29 dealer_cards.append(random.randint(1, 11)) 30 if len(dealer_cards) == 2: 31 print(f"Dealer has [X, {dealer_cards[1]}]") 32 # Players cards 33 while len(player_cards) != 2: 34 player_cards.append(random.randint(1, 11)) 35 if len(player_cards) == 2: 36 print(f"Player has {player_cards}") 37 38 # Stand, Double, Hit 39 while sum(player_cards) < 21: 40 player_choise = str(input("Stand, Double, or Hit?: ")).lower() 41 42 if player_choise == "hit": 43 player_cards.append(random.randint(1, 11)) 44 print(f"Player have {player_cards}") 45 if sum(player_cards) > 21: 46 print(f"Sum of player's cards is over 21") 47 print("------You lose------") 48 # Your current bet is 0$") 49 50 elif player_choise == "double": 51 player_bet = player_bet * 2 52 player_cards.append(random.randint(1, 11)) 53 print(f"You now have a total of {player_cards}") 54 if sum(player_cards) > 21: 55 print(f"Sum of your cards is over 21, {player_cards}") 56 print("------You lose------") 57 # Your current bet is 0$") 58 59 else: 60 print(f"[ The player have a total of {str(sum(player_cards))} ]") 61 62 while sum(dealer_cards) < sum(player_cards): 63 dealer_cards.append(random.randint(1, 11)) 64 print( 65 f"[ The dealer has a total of {str(sum(dealer_cards))} ]") 66 67 if sum(player_cards) > 21: 68 print(f"Sum of your cards is over 21, {player_cards}") 69 print("------You lose------") 70 print(f"Your current bet is 0$") 71 elif sum(dealer_cards) > 21: 72 print(f"Sum of the dealer's cards is over 21") 73 print("------You Win------") 74 # "Your current bet is " + player_bet*2 75 elif sum(dealer_cards) > sum(player_cards): 76 print("Dealer's card is bigger than player's card") 77 print("------You lose------") 78 # Your current bet is 0$") 79 # elif sum(dealer_cards) < sum(player_cards): 80 # print("Player's card is bigger than dealer's card") 81 # print("------You Win------") 82 break 83 84 if sum(dealer_cards) == sum(player_cards): 85 print(f"{player_cards} = {dealer_cards}") 86 print("Push") 87 # print("Your current bet is " + player_bet) 88 elif sum(player_cards) == 21 and sum(dealer_cards) < sum(player_cards): 89 print("Balckjack!") 90 print("------You Win------") 91 # print("Your current bet is " + player_bet*2) 92 93 play_again = str(input("Play again >> Type yes or no: ")).lower() 94 if play_again == "no": 95 bet = False 96
あなたの回答
tips
プレビュー