我四处寻找已经这样做过的人,但我还没有得到结果。基本上遵循网站上的公式(这里是一个链接) http://www.serebii.net/games/damage.shtml .我正在使用 Python 3+,所以这是我的代码。 (注意我遗漏了随机数)我不断收到语法错误。
level = int(input('Please enter your pokemons level :' ))
Attackstat= int(input('Please enter your pokemons special/attack stat : '))
Defensestat= int(input('Please enter your opponents special/defense stat : '))
Attackpower= int(input('Please enter your moves base attack : '))
answer= str('Is your move STAB? : ')
STAB= if answer == yes:
STAB= 1.5
else:
STAB= 1
answer1= int('How effective is your move?')
resistance= if answer1== 4:
resistance= 4
if answer1== 2:
resistance= 2
if answer1== 1:
resistance= 1
if answer1== 0.5:
resistance= 0.5
if answer1== 0.25:
resistance= 0.25
damage= (((2* level/5 +2) * Attackstat * Attackpower/ Defensestat)/50)+2)*STAB*resistance/100
print (damage)
请您参考如下方法:
嗯:
resistance= if answer1== 4:
resistance= 4
if answer1== 2:
resistance= 2
if answer1== 1:
resistance= 1
if answer1== 0.5:
resistance= 0.5
if answer1== 0.25:
resistance= 0.25
在 Python 中给出一个错误。只写:
if answer1== 4:
resistance= 4
if answer1== 2:
resistance= 2
if answer1== 1:
resistance= 1
if answer1== 0.5:
resistance= 0.5
if answer1== 0.25:
resistance= 0.25
更好的是:
if answer1== 4:
resistance= 4
elif answer1== 2:
resistance= 2
elif answer1== 1:
resistance= 1
elif answer1== 0.5:
resistance= 0.5
elif answer1== 0.25:
resistance= 0.25
和(相同):
STAB= if answer == yes:
STAB= 1.5
if answer == "yes":
STAB = 1.5
else:
STAB = 1
更好
resistance = answer1
或
if answer1 in [4, 2, 1, 0.5, 0.25]:
resistance = answer1
