Python is one of the most famous programming languages. It is an interpreted language which is very easy to master if you start learning it after Java and C++. This guide explains how to run Python script line by line on Ubuntu. 

How to Run Python Code Inside the Ubuntu Operating System?

It is very simple. You create a file on the desktop using command-line, open it inside any text editor, write the code, save it, and then execute the file using command-line. 

Use Simple Text Editor

  1. The first step is to confirm, if you have Python installed in your system. The following command is going to help you check what version of Python 3 you have in your system. This command checks what version of Python 3 is installed in your system. First, it asks for the password. After entering, it will tell you the version of Python 3. If Python 3 is not installed, it will return the error.
$ sudo python3 --version

In this case, Python 3.10.12 is installed in the system.

If it is not installed, first install and then start from the next stop. But in most cases, it is pre-installed in Ubuntu. 

  1. Move into the desktop. Here is the command for it. 
$ cd Desktop/
  1. Create a file
$ sudo touch helloworld.py

Notice the new file created at the desktop in the picture below.  

  1. Open this file.
$ sudo gedit helloworld.py

It will open up the text editor

  1. Write the following statement in the text editor to print a line. 

print(“Hello world is my first program on Python, I have made it today”) 

  1. Save it. Save button is  on the upper right corner. 
  1. Run this code with Python3 command in the terminal
$ sudo python3 helloworld.py

Conclusion

You can run python script line by line on Ubuntu by moving to the desktop and creating an executable file there. Hereafter, you open this file in the text editor, write the code, save the file, and then execute it from the terminal.