Environment:
I am having problems running this simple lines of code in the python interpreter, this is an only if statement or alone if statement.
n = 5
if n == 4:
print('n=4')
print('done')
This must print the word "done", but what am I doing wrong?
Python if Statement. The if statement starts with the if keyword followed by the conditional expression. The EXPRESSION must be followed by ( : ) colon. If the EXPRESSION evaluates to True , the STATEMENT gets executed.
Here's an example:if 51<5: print("False, statement skipped") elif 0<5: print("true, block executed") elif 0<3: print("true, but block will not execute") else: print("If all fails.")
In a Python program, the if statement is how you perform this sort of decision-making. It allows for conditional execution of a statement or group of statements based on the value of an expression.
The interpreter gives you a line after blocks to leave blank for the interpreter to know your block is over (or to put an else
, etc.). Putting something there makes it freak out. Just leave it that line blank and wait for the next >>>
before your print('done')
.
>>> n = 5
>>> if n == 4:
... print('n=4')
...
>>> print('done')
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With