Can i use more staments in one line expresion if? | SoloLearn: Learn to code for FREE!

0

Can i use more staments in one line expresion if?

it seems like not :(

2/21/2017 4:37:17 PM

Ian Maguiña

8 Answers

New Answer

+3

You want to say "conditions" maybe? What call you "statement"? You cannot do : if x > 0: if x < 10: But you can do: if x > 0 and x <10: As well as: if 0 < x < 10: And combining as many 'and' and 'or' chained conditions...

+1

If you mean putting more than one statement on a line then yes, but the statements will need to end with a semicolon. print ("1st"); print ("2nd");

+1

@Robin, not it doesn't. x++ is a syntax error in Python. Also, I tried your code, and it says "SyntaxError: invalid syntax" for the "x = 0" You just can't Python...

0

@Robin I think you're confused. That would be a for loop not an if statement.

0

sorry my english isn't good , i was talking about logic conditions , i used &&, || , but recently i saw that would be (and , or )

-1

many times when writting an if statement, you have 3 peramiters if (start condition, logic, end conditon) it would look something like this if (x=0, x < 3, x++) (code to be executed) else............. so if you have an if statement that takes on many parameters, it may be more usefull to use a switch statement.

-1

i mistook the code for javascript. sorry about that. and no i cant pyton at all lol. at least not yet 😐 in javascript x++ would just add 1 to x

-2

@chaoticdawg it works for both