Run your first python program “hello world”
Things you will need:
Raspberry Pi + SD Card
Keyboard + Mouse
Monitor + HDMI Cable
1. Start by opening a Terminal, by click the icon in the taskbar
2. Start by creating a new directory, this is where we are going to store all our scripts for this series of tutorials, make a directory called gpio_python_code:
3. We can use the command ls -l to view the contents of the current directory:
You should be able to see the directory you created
4. Now we need to change our current directory to the newly created gpio_python_code directory:
5. Using the touch command, we can create an empty file. This will be where we are going to code our Hello World script.
6. Once we have created our empty file, we can use the command nano, to open it in a text editor.
7. Now enter the following code:
#!/usr/bin/python #Print Hello world print "Hello World!"
8. Press ctrl+X to exit, you will be prompted to save the file, simply press Y, and then be you will be prompted to give the file a name.
It will automatically use its current name 1_helloworld.py, so just hit enter to accept.
9. To execute your script, simply enter the following command:
sudo python 1_helloworld.py