Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 56ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
p

probability

Recently created Least recently created Recently updated Least recently updated

timmy / 模擬硬幣擲投並計算機率

Last active 6 hours ago coin-flip data-analysis monte-carlo-simulation probability python random-statistics

這段程式碼用於模擬擲硬幣 n 次,並統計正面與反面的機率。程式會計算並顯示正面與反面的出現次數與機率,以驗證隨機性。

0 0 0 1
1 import random
2
3
4 def toss_coin():
5 # 0代表正面,1代表反面
6 return "正面" if random.randint(0, 1) == 0 else "反面"
7
8
9 def simulate_tosses(n):
10 # 初始化計數器

timmy / 隨機模擬擲硬幣

Last active 6 hours ago coin-flip decision-making game-simulation probability python random

這段程式碼模擬擲硬幣(Toss a Coin)的行為,每次執行都會隨機回傳「正面」或「反面」。

0 0 0 1
1 import random
2
3
4 def toss_coin():
5 # 0代表正面,1代表反面
6 return "正面" if random.randint(0, 1) == 0 else "反面"
7
8
9 # 擲硬幣
10 result = toss_coin()