Tohit = random.randrange(12, 32)
分配
Tohit
为整数,但在
if Tohit == "31":
Tohit==31
代码应该可以工作:)
此外,您还需要更改
while str(rolls) > str(0):
到
while rolls > 0
while str(critrolls) > str(0)
到
while critrools > 0
还有你的
而critrools>0
是一个无限循环,因为
critrolls = 2
和
2>0
会导致无限循环,因为你永远不会改变
critrolls
值,您需要在循环中更新该值,或者
critrolls = critrolls - 1
import random
rolls = 2
critrolls = 4
FDMG = 6
DMG = 0
Tohit = random.randrange(12, 32)
#Change to int to int comparison
if Tohit == 31:
# Change to int to int comparison
while critrolls > 0:
DMG = random.randrange(1, 9)
FDMG = FDMG + DMG
#Perhaps you need to decrement critrolls here to break infinite loop
# Change to int to int operation by removing int typecast
critrolls -= 1
print("Your to hit is", Tohit)
print("Your Damage is", FDMG)
elif Tohit <= 30:
# Change to int to int comparison
while rolls > 0:
DMG = random.randrange(1, 9)
FDMG = FDMG + DMG
# Change to int to int operation by removing int typecast
rolls -= 1
print("Your to hit is", Tohit)
print("Your Damage is", FDMG)