This article was updated and rechecked on 25th of June 2022
Added: 28th of April 2020
Updated On: 25th of June 2022
Viewed: 2,772 times
How to create a basic Python3 script in Ubuntu and Ubuntu based distributions
Ubuntu and Ubuntu based distributions include Python3, so you can start programming without installing any additional packages.
In this example we will create a basic python script and run this through the terminal.
To start off, we can check what version of Python3 we have installed on our system, by issuing the following command in the terminal
As you can see from the screenshot, my system is running version
In order to create a Python script we need to find the path to the Python interpreter on our system, so issue the following command in the terminal
Next create a new file on your desktop and save as python.py
Next open the file and copy and paste the code below, noting the path to Python at the top of the script and save the file.
number1 = input("Enter your first number? ")
number2 = input("Enter your second number? ")
sum = int(number1) + int(number2)
print ("The answer is " +str(sum))
Now we need to make the file executable, so enter the following command in the terminal
chmod +x python.py
Now we can test the python script by entering the name of the file
The script asks for two numbers via input, then adds the two numbers together.