How to Write a Basic Python Program

Open the Terminal., Know the commands., Download the latest version of Python from the Internet., Decompress the Python file using the following command: tar -xvf Python-2.7.5.tgz cd Python-2.7.5 Once again, we need to change the working directory...

15 Steps 2 min read Advanced

Step-by-Step Guide

  1. Step 1: Open the Terminal.

    On Linux, you can press the Alt button to open a search bar.

    Type "terminal" and click on Terminal.
  2. Step 2: Know the commands.

    Terminal commands are shown in this document as: command
    -options filename.ext sudo apt-get install build-essential The "sudo" command gives permission to the terminal to modify your computer.

    This is necessary to install any program.

    You will be required to enter your password.

    The "apt-get install" command tells the computer to install the package "build-essential" which is required to install Python. sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev These are programs that Python uses to run correctly.

    They are also known as “dependencies”. , Use the following command: cd ~/Downloads/ The "cd" command changes to the correct working directory so the computer can find and put programs in the right place. wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tgz , This time, we change to the newly created Python directory. , It will alert you of any critical errors. ./configure , It compiles the source code and creates the executables. make , With the following command, all of the applications and libraries associated with Python are moved into the correct places on your computer. sudo make install , Any text editor that can save files with a ".py" extension will do.

    Ubuntu
    12.04 or greater is packaged with the Gedit editor. , In Python, whatever is enclosed in quotes after the word print will be printed out to the screen. , Be careful that the file is not saved as "hello_world.py.txt". ,, Remember to use the "cd" command to change directories.

    If you need a list of all subdirectories at your current location, use the "ls" command. "ls" stands for "list subdirectories". ,
  3. Step 3: Download the latest version of Python from the Internet.

  4. Step 4: Decompress the Python file using the following command: tar -xvf Python-2.7.5.tgz cd Python-2.7.5 Once again

  5. Step 5: we need to change the working directory.

  6. Step 6: Use the ./configure command checks your computer to ensure you have all the necessary components to install Python.

  7. Step 7: Use the make command.

  8. Step 8: Move the applications and libraries.

  9. Step 9: Open a text editor.

  10. Step 10: Type print 'Hello

  11. Step 11: World!'

  12. Step 12: Save the file as "hello_world.py.

  13. Step 13: Open the Terminal again.

  14. Step 14: Navigate to the directory where "hello_world.py" is located.

  15. Step 15: Run the script: python hello_world.py

Detailed Guide

On Linux, you can press the Alt button to open a search bar.

Type "terminal" and click on Terminal.

Terminal commands are shown in this document as: command
-options filename.ext sudo apt-get install build-essential The "sudo" command gives permission to the terminal to modify your computer.

This is necessary to install any program.

You will be required to enter your password.

The "apt-get install" command tells the computer to install the package "build-essential" which is required to install Python. sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev These are programs that Python uses to run correctly.

They are also known as “dependencies”. , Use the following command: cd ~/Downloads/ The "cd" command changes to the correct working directory so the computer can find and put programs in the right place. wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tgz , This time, we change to the newly created Python directory. , It will alert you of any critical errors. ./configure , It compiles the source code and creates the executables. make , With the following command, all of the applications and libraries associated with Python are moved into the correct places on your computer. sudo make install , Any text editor that can save files with a ".py" extension will do.

Ubuntu
12.04 or greater is packaged with the Gedit editor. , In Python, whatever is enclosed in quotes after the word print will be printed out to the screen. , Be careful that the file is not saved as "hello_world.py.txt". ,, Remember to use the "cd" command to change directories.

If you need a list of all subdirectories at your current location, use the "ls" command. "ls" stands for "list subdirectories". ,

About the Author

B

Brian Gordon

Professional writer focused on creating easy-to-follow pet care tutorials.

46 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: