Opengist

Explore

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

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
r

random

Recently created Least recently created Recently updated Least recently updated

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()