Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
FIGURE 4.3 Output for the Python script script0402.py.


  1. At the command-line prompt, type nano py3prog/script0402.py and press
    Enter. The command puts you into the nano text editor, where you can modify the
    script0402.py script.

  2. Go to the Output Variable Description portion of the script and add a
    separator to the end of each line. The lines of code to be changed and how they
    should look when you are done are shown here:


Click here to view code image
print ("name: amount", "data type:", type (amount), "value:", amount,
sep='\t')



print ("name: vessels", "data type:", type (vessels), "value:", vessels,
sep='\t')



print ("name: liquid", "data type:", type (liquid), "value:", liquid,
sep='\t')



print ("name: location", "data type:", type (location), "value:",
location,sep='\t')



  1. Write out the modified script by pressing Ctrl+O. Press Enter to write out the
    contents to the script0402.py script.

  2. Exit the nano text editor by pressing Ctrl+X.

  3. Type python3 py3prog/script0402.py and press Enter to run the script.
    You should see output like the output shown in Figure 4.4. Much neater!

Free download pdf