Python 我怎么能在你每次进入时随机进行攻击;“击中”吗;?
在开始时,当你第一次键入“hit”时,它是随机的,但之后它会给你与之前相同的结果Python 我怎么能在你每次进入时随机进行攻击;“击中”吗;?,python,Python,在开始时,当你第一次键入“hit”时,它是随机的,但之后它会给你与之前相同的结果 import time import random while yourhealthpoints >= 0 and (gargoil): attack = input("Type hit to attack your opponent") if attack == "hit" or attack == "HIT" or attac
import time
import random
while yourhealthpoints >= 0 and (gargoil):
attack = input("Type hit to attack your opponent")
if attack == "hit" or attack == "HIT" or attack == "Hit":
gargoilhealthpoints = gargoilhealthpoints - yourattack
print("You hit the gargoil for %s health-points" % yourattack)
time.sleep(2)
if gargoilhealthpoints <= 0:
gargoil = False
print("You defeated the gargoil!")
if gargoil:
yourhealthpoints = yourhealthpoints - gargoilattack
print("The gargoil hit you for %s health-points, you have %s health-points left..." %(gargoilattack, yourhealthpoints))
if yourhealthpoints <= 0:
print("You were killed by: GARGOIL...")
导入时间
随机输入
当yourhealthpoints>=0和(gargoil)时:
攻击=输入(“键入命中以攻击对手”)
如果攻击=“命中”或攻击=“命中”或攻击=“命中”:
gargoilhealthpoints=gargoilhealthpoints-您的攻击
打印(“您为%s生命点“%yourattack”击中了gargoil)
时间。睡眠(2)
如果gargoilhealthpoints我看不到随机攻击是在哪里产生的,但是如果你有变量yourattack
,请确保在你将设为0且(gargoil):
否则,它将生成一个随机数,并连续使用该随机数。
也可以稍微短一点,而不是
attack = input("Type hit to attack your opponent")
if attack == "hit" or attack == "HIT" or attack == "Hit":
gargoilhealthpoints = gargoilhealthpoints - yourattack
你能行
attack = input("Type hit to attack your opponent")
attack = attack.lower()
if attack == "hit":
gargoilhealthpoints = gargoilhealthpoints - yourattack
谢谢!这帮了大忙。我不小心忘了把开头放进去。再次感谢您的帮助。@Hermes当然!很高兴我能帮忙