Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple if statement on python interpreter

Environment:

  • Fedora 27 (GNU/Linux)
  • terminal
  • python3.6.3

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')

enter image description here

This must print the word "done", but what am I doing wrong?

like image 961
christianbueno.1 Avatar asked Dec 16 '17 00:12

christianbueno.1


People also ask

How do you write an if statement in Python interpreter?

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.

What is an example of an if statement in Python?

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.")

What is an if clause in Python?

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.


1 Answers

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
like image 193
Brett Beatty Avatar answered Nov 01 '22 23:11

Brett Beatty