Issue
I am trying to run this code but Jupyter keeps giving me the following syntax error at the else condition.
File "<ipython-input-24-beb6bcd9d77b", line 24
else:
^
SyntaxError: invalid syntax
I was running a similar code earlier and else worked there but I don't understand what's wrong with this code.
valid = True
while valid:
if predators != 0 and prey != 0:
preyCount.append(prey)
predatorCount.append(predators)
prey = prey * (1 + preyGrowth - predationRate * predators)
predators = predators * (1 - predShrink + predFedBirthRate * preyCount[-1]
else:
valid = False
Solution
As stated in the comments, always look on the line above if you know a line is definitely correct syntax. In this case, predators = predators * (1 - predShrink + predFedBirthRate * preyCount[-1]
is missing a parenthesis at the end -- it should be predators = predators * (1 - predShrink + predFedBirthRate * preyCount[-1])
). This causes Python to think that you are trying to do:
predators = predators * (1 - predShrink + predFedBirthRate * preyCount[-1] else
which makes no sense.
Answered By - TheTechRobo36414519
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.