You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to combine or and and conditionals inside of if statements I get wonky calculations.
if (3==3 or 2==2) and 5==5:
print('hi')
Gives SyntaxError: Unexpected token
If I add a set of parenthesis:
if ((3==3 or 2==2) and 5==5):
print('hi')
Then it works fine.
But, I just had a case where I realized it might be parsing things improperly. I was running this code in the level zero-sum:
if ((soldiers < 2 or soldiers <= archers/5) and self.gold >= self.costOf("soldier")):
self.summon("soldier")
This was attempting to summon a soldier even when I didn't have enough gold. But when I tried a simplified version in the Interactive testing, I couldn't replicate it, maybe I just had something wrong in my code, but when I simply split that statement to:
if (soldiers < 2 or soldiers <= archers/5)
if self.gold >= self.costOf("soldier"):
self.summon("soldier")
It no longer attempted to summon the soldier.
The text was updated successfully, but these errors were encountered:
When trying to combine
or
andand
conditionals inside ofif
statements I get wonky calculations.Gives
SyntaxError: Unexpected token
If I add a set of parenthesis:
Then it works fine.
But, I just had a case where I realized it might be parsing things improperly. I was running this code in the level zero-sum:
This was attempting to summon a soldier even when I didn't have enough gold. But when I tried a simplified version in the Interactive testing, I couldn't replicate it, maybe I just had something wrong in my code, but when I simply split that statement to:
It no longer attempted to summon the soldier.
The text was updated successfully, but these errors were encountered: