import random
randatk=random.randint(1,10)
randheal=random.randint(1,10)
mnstrhp=100
playerhp=100
while mnstrhp>0:
atkorheal=input("would you like to attack the monster or heal yourself? ")
if 'attack' in atkorheal:
print("you did" , randatk , "damage to the monster!")
print("the monster's current health is " , mnstrhp-randatk)
if 'heal' in atkorheal:
print("you healed for" , randheal , "health!")
print("your current hp is " , playerhp+randheal)
我的目标是每次程序循环时获得不同的随机结果,但是,每次程序循环时,它始终是相同的数字。有没有办法每次都能获得不同的价值?
答案 0 :(得分:1)
randint()调用应该在您的循环中。您目前仅生成一个随机数并使用n次。