fork download
  1. import random
  2.  
  3. def calculate_odds(rider_skill, horse_skill):
  4. random_num = random.randint(5, 10)
  5. odds = (rider_skill * random_num) / horse_skill
  6. return odds
  7.  
  8. # シミュレーション回数
  9. num_simulations = 10000
  10. odds_list = []
  11.  
  12. for _ in range(num_simulations):
  13. rider_skill = random.choices([1, 2, 3, 4], weights=[1, 2, 2, 3])[0]
  14. horse_skill = random.randint(1, 10)
  15. odds = calculate_odds(rider_skill, horse_skill)
  16. odds_list.append(odds)
  17.  
  18. # 平均値と最大値を計算
  19. average_odds = sum(odds_list) / len(odds_list)
  20. max_odds = max(odds_list)
  21.  
  22. print("平均値:", average_odds)
  23. print("最大値:", max_odds)
Success #stdin #stdout 0.11s 11908KB
stdin
Standard input is empty
stdout
平均値: 6.3038376984126625
最大値: 40.0