Erle Robotics Learning Python GitBook Free

Displaying values on the screen

For displaying a desired sentence os text on the scrren you should use a simple sintaxis, like the following one:

print " Text goes here"

You can also display numbers and varibales:

print number
print varibale

The , character after our print statement means that our next print statement keeps printing on the same line.

Practice 1

Create a file with a "Hello world " message and display it on the screen:

[email protected]:~# touch Hello.py
[email protected]:~# echo 'print "Hello World!"' > Hello.py
[email protected]:~# python Hello.py
Hello World!
[email protected]:~#

Practice 2

Create a file containing three numbers and print them on the screen:

[email protected]:~/Python_files# touch Num.py
[email protected]:~/Python_files# echo 'print 1' >> Num.py
[email protected]:~/Python_files# echo 'print 4' >> Num.py
[email protected]:~/Python_files# echo 'print 6' >> Num.py
[email protected]:~/Python_files# python Num.py
1
4
6

Practice 3

Display a variable on your screen:

[email protected]:~/Python_files# python
Python 2.7.3 (default, Sep 26 2013, 21:37:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Like this you initialize the python program.

>>> var="Hello"
>>> print "this is the variable: ", var
this is the variable: Hello

Notice that we have use the two methods of running Python.