python - Nested if; how to proceed to the next elif from true if -
I'm learning "dragon hard way", my first programming language is also "block" inside the "if" block I'm trying to find out on the next "Alif" block.
I have written a small example:
door = raw_input ("& gt;") if door == "1": door == "2" alif door == "2": Printed "Red Yes." Inside my actual code, if I block another if \ elif inside the "if" block, and inside one of them I would start an if \ elif condition I want to set up Alif, ie (Elif door == '2')
In the short example given above, I should have the output:
"& gt; 1
Lol yeah. "
I am sorry if that was not clear enough.
Try the following: <= P>
door = raw_input ("& gt; ; ") If door ==" 1 ": door =" 2 "if door ==" 2 ": print" lol yeah. " if / elif is conditional, it means that if if -clause is executed first, then elif < / Code> is not reached. Here's an example, I have a code in your code so that you can test it more easily.
& gt; & Gt; & Gt; Def test_doors (): ... door = raw_input ("& gt;") ... if door == "1": ... door = "2" ... if door == "2": .. Print "Red Yes." ... ... ... & gt; & Gt; & Gt; Test_doors () & gt; 1 Hello / Note that if you have an error in your first if -clause, where you try to set the value of door Are 2 . You need to leave the second = , otherwise the variables can never be changed. In fact, it is evaluated and the interpreter returns wrong because it thinks that you want to ask if door is of 2 Suppose you can try it in interpreter like this: & gt; & Gt; & Gt; Door = 1> & Gt; & Gt; Doorway == 2 false & gt; & Gt; & Gt; Door == 1 true
Comments
Post a Comment