我有点像一个python n00b,我正在创建一种战斗场景,而IDLE一直在说一个简单的else
块。这是代码。
import random
chanceToHitP1 = ([2, 3, 4])
chanceToHitP2 = ([2, 3, 4, 5, 6, 7, 8, 9, 10])
playerHP = 30
enemyHP = 40
playerAttackPower1 = 20
#Accuracy for move 1 is 75%
playerAttackPower2 = 10
#Accuracy for move 2 is 100%
playerAttackPower3 = 15
#Accuracy for move 3 is 90%
enemyAttackPower1 = 20
#Accuracy for move 1 is 75%
enemyAttackPower2 = 10
#Accuracy for move 2 is 100%
enemyAttackPower3 = 15
#Accuracy for move 3 is 90%
def player_turn():
print " what move would you like to make?"
moveMade = input()
# Move 1
if moveMade == 1:
accuracyChance = random.choice ([2, 3, 4, 1])
if accuracyChance in chanceToHitP1:
print "You hit!"
enemyHP = (enemyHP - playerAttackPower1
else:
print "your attack missed.."
# Move 2
elif moveMade == 2:
print "Your attack hit!"
enemyHP = (enemyHP - playerAttackPower2)
# Move 3
elif moveMade == 3:
accuracyChance = random.choice ([2, 3, 4, 5, 6, 7, 8, 9, 10, 1])
if accuracyChance in chanceToHitP2:
print "You hit!"
enemyHP = (enemyHP - playerAttackPower3)
else: print "You missed" [This is where it has an error]
player_turn()
这是不完整的,player_turn()
将处于循环中,直到某人的HP减少了0。当我运行它时,IDLE将突出显示我指出的else
。我不知道为什么,我真的很感激一些帮助...谢谢!
答案 0 :(得分:0)
enemyHP = (enemyHP - playerAttackPower1
你这里有一个不匹配的括号。添加一个,或删除左边的。
enemyHP = enemyHP - playerAttackPower1
或者
enemyHP = (enemyHP - playerAttackPower1)