fork download
  1. import random
  2.  
  3. small_count, big_count, even_count, odd_count = 0, 0, 0, 0
  4.  
  5. for _ in range(1000):
  6. # 生成三个随机数并求和
  7. total_sum = sum(random.randint(0, 27) for _ in range(3))
  8.  
  9. # 判断大小
  10. size = "小" if total_sum < 14 else "大"
  11.  
  12. # 判断单双
  13. parity = "双" if total_sum % 2 == 0 else "单"
  14.  
  15. if size == "小":
  16. small_count += 1
  17. else:
  18. big_count += 1
  19.  
  20. if parity == "双":
  21. even_count += 1
  22. else:
  23. odd_count += 1
  24.  
  25. # 计算结果
  26. size_majority = "小" if small_count > big_count else "大" if big_count > small_count else "数量相同"
  27. parity_majority = "双" if even_count > odd_count else "单" if odd_count > even_count else "数量相同"
  28.  
  29. print(f"一千次运算结果中,大小判定:小的出现了{small_count}次,大的出现了{big_count}次,{size_majority}。")
  30. print(f"一千次运算结果中,单双判定:双的出现了{even_count}次,单的出现了{odd_count}次,{parity_majority}。")
Success #stdin #stdout 0.14s 14228KB
stdin
Standard input is empty
stdout
一千次运算结果中,大小判定:小的出现了18次,大的出现了982次,大。
一千次运算结果中,单双判定:双的出现了484次,单的出现了516次,单。