Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with compound conditions in if statements. #59

Open
nemoyatpeace opened this issue Mar 28, 2015 · 0 comments
Open

Problems with compound conditions in if statements. #59

nemoyatpeace opened this issue Mar 28, 2015 · 0 comments
Labels

Comments

@nemoyatpeace
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants