3. Interactive Mode and Editing Mode

3.1. Python interpreter

  • The interpreter is a program that accepts commands written in Python and executes them line by line

  • The interpreter verifies that we have written the program correctly, displaying error messages if there is a problem

  • There are two modes in the Python interpreter: interactive mode and editing mode

  • In the previous examples, we used interactive mode

  • An advantage of interactive mode is being able to test commands and get an instant response

3.1.1. Calculator in the interpreter

>>> 2+3 # Don't forget to press enter
5
>>> 5-3
2
>>> 10-4+2
8
>>> 2*10 # Asterisk for multiplication
20
>>> 10/4 # Slashed line for division
2.5
>>> 2**3 # Exponentiation
8
>>> 10%3 # Modulus (remainder of division)
1
>>> 16%7
2

Now try it for yourself! Write these operations in the interpreter and use interactive mode as a calculator

3.2. Editing Mode

System Message: ERROR/3 (/home/runner/work/PyZombis/PyZombis/_sources/lectures/TWP05/TWP05_3_en.rst, line 48)

Duplicate ID – see lectures/TWP05/TWP05_3, line 55

.. activecode:: ac_l05_3
   :nocodelens:

   Try pressing enter inside the editing block.
   Note that nothing happens when you press enter at the end of the line.
   In editing mode, it is necessary to "execute" the program (To do this, press the Run button).

   ~~~~
   print("first message")

3.3. Precautions when writing programs

  • Upper case and lower case letters are different

  • Quotes are very important and should not be overlooked. Every time you open quotes, don’t forget to close them

  • Parentheses are not optional in Python. Every open parenthesis must be closed

  • Spaces are very important. The Python language is based on the amount of white space before the beginning of each line to perform different operations. This is known as indentation.

You have attempted of activities on this page