有没有办法设置这样的if语句,其中1 if语句包含多个整数?
variable = random.randrange(1,10)
if variable is between 1 - 3
then do this
if variable is between 4-5
then do this
if variable is between 6-9
then do this
或者类似的东西
a = 1,2,3,4,5,6,7,8,9,10
variable = random.randrange(1,10)
if variable == a:
then do this
答案 0 :(得分:0)
如果为每个玩家选择一个随机数,那么具有最大值的玩家将首先进行攻击。
或者,如果这不是基于回合,则设置一个阈值,如果随机数超过阈值,则玩家可以攻击。
阈值也可以是随机数。例如:
player1.attack = randn ()
[player2 etc]
minval = randn ()
for player in players:
if player.attack > minval:
[...attack...]
底部的问题很容易实现,基本上与您编写的一样:
variable = random.randrange(1,10)
if 0 <= variable < 3:
then do this
if 3 <= variable < 5:
then do this
if 5 <= variable < 9:
then do this