Skip to content

Exercise 1: Execute Python scripts


Related course:

Execute Python scripts

Type the text below into a text editor and save as hello.py. Python files usually have the .py extension.

#!/usr/bin/env python3

print('hello world')

If you are using Windows and Notepad++ it may look something like this:

You can use any text editor to create a Python program. I recommend using a text editor that supports syntax highlighting (text colouring) and line numbers.

To start the program, we have to open the command line and type:

python hello.py

What you see if successful

You should see a line of text showing “hello world”.

Study drill

Try the exercises below:

1. Make a Python program that prints your name.
2. Make a program that displays the lyrics of a song.

After completing these continue with the next exercise.

Getting started
Variables

8 Comments

  1. Kolyu Kolyu

    python: can’t open file ‘hello.py’: [Errno 2] No such file or directory

  2. Sally Paveley Sally Paveley

    I followed the instructions but was not able to persuade the command line to display anything other than:

    C:\WINDOWS\system32>python hello.py
    ‘python’ is not recognized as an internal or external command,
    operable program or batch file.

    • Frank Frank

      Hi Sally Paveley,

      Have you been able to resolve your problem?

  3. Tried starting the program, but it didn’t work. Typed exact code from #!… world’) into text editor = Atom… opened command prompt and typed python hello.py, but it didn’t work. I’ve got Python 3.5. Also below this reply box there are two spots for name and no spot for the email…

    • admin admin

      This will work if the python file is in the current directory (pwd).

  4. ihsan ihsan

    hi, dear friends….
    currently beginner level in python but working hard with your exercises,
    thanks for everything….

  5. Frank Frank

    Nice work on explaining the basic concepts by the author. Thumbs up.

Leave a Reply