質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

939閲覧

python ブラックジャック

Jim8372

総合スコア0

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

1クリップ

投稿2020/08/08 05:26

編集2020/08/08 16:56

改善のよちがあったらお願いします。```

よろしくお願いします。

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

glyzinieh

2020/08/08 05:44

プレビューを見ながら、質問を編集コードを見やすくしてください。よろしくお願いします。
can110

2020/08/09 02:22

インデントがなくなっていますので修正ください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問