Python
1import random 2 3print("所持金:", end = '') 4iniCash = int(input()) 5print("最初の掛け金:", end = '') 6iniBet = int(input()) 7print("目標金額:", end = '') 8goal = int(input()) 9 10results = "" 11 12cash = iniCash 13bet = iniBet 14 15while True: 16 x = random.randrange(2) 17 18 if (x == 0): 19 20 cash -= bet 21 22 if (bet * 2 > cash): 23 bet = cash 24 else: 25 bet *= 2 26 27 results += "X" 28 29 else: 30 cash += bet 31 bet = iniBet 32 results += "0" 33 34 if (cash == 0): 35 results = "所持金がなくなりましたT_T: " + results 36 break 37 elif (cash >= goal): 38 results = "所持金が目標金額を上回りました!: " + results 39 break 40 41print(results)
これをN人で行い、何人の所持金が目標を上回るかを調べたいのですが、どう繰り返しを行えばよいのかがわかりません
回答3件
あなたの回答
tips
プレビュー