Thursday, December 18, 2014

Run Hello World Python on Raspberry pi/ Qemu

There are two different ways you can write programs for Python. You can create text files that contain the code, and then run these files with Python, or you can use an Integrated Development Environment (IDE) such as IDLE 3. Either way will result in the code being run in the same way and it's just a matter of personal preference.




If you want to write the programs as text files, you need to use a text editor such as Leafpad. A word processor such as LibreOffice's Writer is unsuitable because the various formatting it uses will confuse Python. As an example, open Leafpad and create a new file that just has the line:

print("Hello World!")

Once you've created your file, just save it with the extension .py; for example testpython.py. You can then run it by opening LXTerminal and navigating to where the file is saved. Then you run python <filename>. You can use the cd command to move to different directories. For example, if you save the file in a folder called programming in your home directory, you could run it by typing the following into LXTerminal:
 
cd programming
python3 testpython.py

 
If everything has worked correctly, you should see the following line appear on the screen:
Hello World!

otherwise just open python shell IDLE 3 and command  print("Hello World!") press Enter you will see the output as 
 Hello World!  
 

No comments:

Post a Comment