簡體   English   中英

我如何讓它在 Python 中從 1 和 2 中選擇一個隨機數?

[英]How would I get it to choose a random number out of 1 and 2 in Python?

所以“玩家”必須輸入一個數字 1 或 2。我需要使用 Python 來制作它,這樣它會隨機選擇一個數字,這樣一個數字就會“好”,玩家活着,另一個“壞”,所以玩家死了。

import random

c = random.choice([1, 2])

或者

c = random.randrange(1, 3)

這是您可以在 Google 上搜索或查閱文檔的內容……但是,這是一個基本實現。

import random
x = random.randint(1, 2)
import random
variable_name = random.randint(x, y)
# x is the min and y is the max

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM