无效语法。未突出显示区域
在这里的某个地方。顺便说一下,这是一个板球游戏。代码中没有任何地方被高亮显示。我该怎么办?提前谢谢你的回答。我需要这个来完成作业。之前运行得很好,直到我编辑了显示球员得分的部分。我本来打算添加已经出局的球员数量,但在这个过程中我搞错了。谢谢。
playruns = playtemp
playscore = playscore + playruns
print("You scored" ,playruns, "runs.", team, "is on", playscore," runs.")
elif playruns == 5:
print("Your player is out! ", team,"'s current score is:", playscore,"runs")
playouts = playouts + 1
if playouts == 5:
print("You are all out. Now it is your turn to bowl.")
while compouts != 5:
print("The Androidz scored", compruns,"runs. The total score of the Androidz is", compscore,"runs.")
compruns = 0
comptemp = 0
compouts = compouts + 1
if compouts == 5:
print("Game over man, game over.")
print("Your score was:", playscore,)
print("The Androidz score was:", compscore.)
if playscore > compscore:
playagain = input("You are the winner.
print("The Androidz scored", compruns,"runs. The total score of the Androidz is", compscore.)
compruns = 0
comptemp = 0
compouts = compouts + 1
if compouts == 5:
print("The Androidz are all out. Congratulations.")
while playouts != 5:
print("You are now batting.")
playmindset = input("For this ball would you like to play agressively 'a', or defensively 'd'")
if playmindset == "a":
playtemp = random.choice([1,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,])
elif playmindset == "d":
playtemp = random.choice([1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,5,5,5,])
playruns = playtemp
playscore = playscore + playruns
if playruns != 5:
print("You scored" ,playruns, "runs.", team, "is on", playscore,"runs")
elif playruns == 5:
print("Your player is out! ", team,"'s current score is:", playscore.)
playouts = playouts + 1
if playouts == 5:
print("Game over man, game over.")
print("Your score was:", playscore,)
print("The Androidz score was:", compscore,)
if playscore > compscore:
playagain = input("You are the winner. Play againg?. 'y' for yes, 'n' for no.")
elif playscore < compscore:
playagain = input("You are the loser. Play againg?. 'y' for yes, 'n' for no.")
elif coinguess != headsortails:
while compouts != 5:
print("You lost the toss. You are bowling.")
print("The Androidz are at the crease. The hot sun beams down upon the ground.\nVictory is a must for", team, "if" , captainname, "wishes to remain as captain.")
bowltodo = input("Would you like to bowl or forfeit?")
comptemp = random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,])
if bowltodo == "bowl":
compruns = comptemp
compscore = compruns + compscore
print("The Androidz scored", compruns,"runs. The total score of the Androidz is",compscore,"runs.")
compruns = 0
comptemp = 0
compouts = compouts + 1
if compouts == 5:
print("The Androidz are all out. Congratulations.")
while playouts != 5:
print("You are now batting.")
playmindset = input("For this ball would you like to play agressively 'a', or defensively 'd'")
if playmindset == "a":
playtemp = random.choice([1,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,6,6,6,6,])
elif playmindset == "d":
playtemp = random.choice([1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,5,5,])
playruns = playtemp
playscore = playscore + playruns
if playruns != 5:
print("You scored" ,playruns, "runs.", team, "is on", playscore.)
elif playruns == 5:
print("Your player is out! ", team,"'s current score is:", playscore.)
playouts = playouts + 1
if playouts == 5:
print("Game over man, game over.")
print("Your score was:", playscore,)
print("The Androidz score was:",compscore,)
if playscore > compscore:
playagain = input("You are the winner. Play againg?. 'y' for yes, 'n' for no.")
elif playscore < compscore:
playagain = input("You are the loser. Play againg?. 'y' for yes, 'n' for no.")
1 个回答
4
你有几个语法错误。第一个错误出现在第33行。
elif playmindset == "d":
playtemp = random.choice([1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,5,5,])
playruns = playtemp
playscore = playscore + playruns
print("You scored" ,playruns, "runs.", team, "is on", playscore," runs.")
elif playruns == 5: # this line
print("Your player is out! ", team,"'s current score is:", playscore,"runs")
playouts = playouts + 1
第二个elif
引发了语法错误,因为在它之前没有if
。也许你是想把这三行代码放在第一个elif
里面,或者把第二个elif
改成一个新的if
。这个需要你自己来修正。
此外,程序中的多个地方(第52、66、84、120、122行)也出现了语法错误,因为你这样打印东西:
print("The Androidz score was:", compscore.)
在compscore
后面的.
暗示你要在它上面调用一个函数,或者某个属性之类的。因为你并没有这样做,所以引发了语法错误。我想你只是想在行末打印一个点,如果是这样的话,只需要把它们改成:
print("The Androidz score was:", compscore + ".")