0

If I have a loop that depends on two variables, for example: while x is higher than 0 and y is higher than 0: do some stuff. but when x is equal or lower than 0 and y is still higher than 0, do stuff_X; and when x is still higher than 0 but y goes equal or lower than 0, do stuff_Y.

How can I write that in python language? I don't know how to use "or" and "and" in python, so I think they can be useful. I tried with "while" but I don't know how to end it.

while x > 0 (and?) y > 0: some stuff here if x <= 0: stuff_X if y <= 0: stuff_Y 
1

2 Answers 2

1

You must use an or:

while x > 0 or y > 0: some stuff here if x <= 0: stuff_X if y <= 0: stuff_Y 

It will end when both x and y are less or equal to 0.

Sign up to request clarification or add additional context in comments.

1 Comment

The OP says "while x is higher than 0 and y is higher than 0: do some stuff", so you need an if statement gating it, and the other if statements should check both variables as the "stuff" is probably rebinding x and y.
0

(can't yet comment to add onto Christian's answer) Here's a tutorial that might help you understand and/or further:

Tutorial

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.