Download Lab 1: Excution of Python Statements and Scripts on Ada

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Lab 1: Excution of Python
Statements and Scripts on Ada
Table of Contents
1. Remote Accessing Using Windows.......................................................................................................2
2. Load Python Module..............................................................................................................................2
2.1 Commands to List Python Modules................................................................................................2
2.1.1 Module Spider python.............................................................................................................2
2.1.2 Module Spider Python.............................................................................................................2
2.1.3 Module Avail python...............................................................................................................3
2.1.4 Module Avail Python...............................................................................................................9
2.2 Command to Load a Python Module..............................................................................................9
2.3 Command to View the Loaded Python Module..............................................................................9
2.4 Command to Purge Python Module from Your Enviroment...........................................................9
3 Find the Python Version in Use.............................................................................................................10
4 Find the Location of Python in Use......................................................................................................10
5 Run Python Interpretor..........................................................................................................................10
6 Exit Python Interpretor..........................................................................................................................10
7 Interactive Execution of Python Statements.........................................................................................10
7.1 Print...............................................................................................................................................10
7.1.1 Excution in Python 2.............................................................................................................10
7.1.2 Excution in Python 3..............................................................................................................11
7.1.3 Exercises................................................................................................................................11
7.2 Division /.......................................................................................................................................11
7.2.1 Excution in Python 2..............................................................................................................11
(7.2.3) Try / with Python 3.............................................................................................................12
7.2.3 Exercises................................................................................................................................12
7.3 If....................................................................................................................................................12
7.3.1 Try the following Statements using Python 2............................................................................12
7.3.2 Exercises................................................................................................................................13
7.4 While.............................................................................................................................................13
7.4.1 Try the following Statements using Python 2........................................................................13
7.4.2 Exercises................................................................................................................................14
7.5 For.................................................................................................................................................14
7.5.1 Try the following Statements using Python 2........................................................................14
7.5.2 Exercises................................................................................................................................14
8 Execution of Python Scripts..................................................................................................................15
8.1 Python Name_of_Script................................................................................................................15
8.2 Executable Script...........................................................................................................................15
1. Remote Accessing Using Windows
See the documents at: http://sc.tamu.edu/help/access/windows.php.
Note: in the document for putty, “hydra” should be replaced with “ada”.
2. Load Python Module
2.1 Commands to List Python Modules
2.1.1 Module Spider python
[yangliu@ada4 ~]$ module spider python
-------------------------------------------------------------------------------------------------python:
-------------------------------------------------------------------------------------------------Description:
Python is a programming language that lets you work more quickly and integrate your systems
more effectively. - Homepage: http://python.org/
Versions:
Python/2.7.6-ictce-7.1.2
Python/2.7.10-intel-2015B
Other possible modules matches:
Biopython IPython Python ScientificPython netcdf4-python python-dateutil python-meep
-------------------------------------------------------------------------------------------------To find other possible module matches do:
module -r spider '.*python.*'
-------------------------------------------------------------------------------------------------To find detailed information about python please enter the full name.
For example:
$ module spider Python/2.7.6-ictce-7.1.2
2.1.2 Module Spider Python
[yangliu@ada4 ~]$ module spider Python
-------------------------------------------------------------------------------------------------Python:
-------------------------------------------------------------------------------------------------Description:
Python is a programming language that lets you work more quickly and integrate your systems
more effectively. - Homepage: http://python.org/
Versions:
Python/2.7.3-ictce-7.1.2
Python/2.7.6-ictce-6.3.5
Python/2.7.6-ictce-7.1.2
Python/2.7.8-foss-2014c
Python/2.7.8-goolf-1.7.20
Python/2.7.8-ictce-7.1.2
Python/2.7.8-intel-2014b
Python/2.7.8-intel-2015A
Python/2.7.8-intel-2015B
Python/2.7.9-GCC-4.9.2-bare
Python/2.7.9-goolf-1.7.20
Python/2.7.9-intel-2015A-bare
Python/2.7.9-intel-2015A
Python/2.7.9-intel-2015B
Python/2.7.10-GCC-4.8.4-bare
Python/2.7.10-goolf-1.0.20
Python/2.7.10-goolf-1.7.20
Python/2.7.10-intel-2015B-bare
Python/2.7.10-intel-2015B
Python/3.3.2-ictce-6.3.5
Python/3.3.2-ictce-7.1.2
Python/3.4.3-intel-2015B
Other possible modules matches:
Biopython IPython ScientificPython netcdf4-python python python-dateutil python-meep
-------------------------------------------------------------------------------------------------To find other possible module matches do:
module -r spider '.*Python.*'
-------------------------------------------------------------------------------------------------To find detailed information about Python please enter the full name.
For example:
$ module spider Python/3.4.3-intel-2015B
--------------------------------------------------------------------------------------------------
2.1.3 Module Avail python
[yangliu@ada4 ~]$ module avail python
---------------------------- /general/software/x86_64/tamusc/modulefiles ----------------------------Python/2.7.6-ictce-7.1.2 Python/2.7.10-intel-2015B (D)
--------------------------- /general/software/x86_64/easybuild/modules/all --------------------------ABySS/1.5.1-ictce-6.3.5-Python-2.7.6
ABySS/1.9.0-goolf-1.7.20-Python-2.7.10
ABySS/1.9.0-intel-2015B-Python-2.7.10
(D)
ASE/3.8.1.3440-ictce-6.3.5-Python-2.7.6
ASE/3.8.1.3440-ictce-7.1.2-Python-2.7.8
AUGUSTUS/3.1-intel-2015B-Python-2.7.10
AUGUSTUS/3.1-intel-2015B-Python-3.4.3
Armadillo/4.300.8-ictce-6.3.5-Python-2.7.6
Armadillo/4.300.8-intel-2015B-Python-2.7.10
Armadillo/4.650.4-intel-2015B-Python-2.7.10
Armadillo/5.400.2-intel-2015B-Python-2.7.10
BLAST+/2.2.31-intel-2015B-Python-2.7.10
BLAST+/2.2.31-intel-2015B-Python-3.4.3
BUSCO/1.1b1-intel-2015B-Python-3.4.3
Biopython/1.65-intel-2015B-Python-2.7.10
Boost/1.49.0-ictce-6.3.5-Python-2.7.6
Boost/1.53.0-ictce-6.3.5-Python-2.7.6
Boost/1.55.0-ictce-6.3.5-Python-2.7.6
Boost/1.55.0-intel-2014b-Python-2.7.8
Boost/1.55.0-intel-2015a-Python-2.7.8
Boost/1.57.0-intel-2015a-Python-2.7.9
Boost/1.58.0-goolf-1.7.20-Python-2.7.9
Boost/1.58.0-goolf-1.7.20-Python-2.7.10
Boost/1.58.0-intel-2015B-Python-2.7.10
Boost/1.58.0-intel-2015B-Python-3.4.3
Boost/1.59.0-intel-2015B-Python-2.7.10
Boost/1.59.0-intel-2015B-Python-3.4.3
CGAL/4.4-ictce-6.3.5-Python-2.7.6
CVXOPT/1.1.5-ictce-6.3.5-Python-2.7.6
CVXOPT/1.1.5-ictce-7.1.2-Python-2.7.8
Cheetah/2.4.4-intel-2015B-Python-2.7.10
Cython/0.19.2-ictce-6.3.5-Python-2.7.6
Cython/0.19.2-ictce-7.1.2-Python-2.7.8
Cython/0.19.2-intel-2015A-Python-2.7.8
Cython/0.19.2-intel-2015A-Python-2.7.9
Cython/0.22-intel-2015A-Python-2.7.9
Docutils/0.9.1-ictce-6.3.5-Python-2.7.6
Docutils/0.9.1-ictce-7.1.2-Python-2.7.8
Docutils/0.11-ictce-6.3.5-Python-2.7.6
EMAN2/2.11-intel-2015B-Python-2.7.10
EMBOSS/6.6.0-intel-2015B-Python-2.7.10
EMBOSS/6.6.0-intel-2015B-Python-3.4.3
FFC/1.4.0-ictce-6.3.5-Python-2.7.6
FIAT/1.1-intel-2014b-Python-2.7.8
FIAT/1.4.0-ictce-6.3.5-Python-2.7.6
FIAT/1.4.0-intel-2015A-Python-2.7.9
FIAT/1.5.0-goolf-1.7.20-Python-2.7.10
FIAT/1.5.0-intel-2015B-Python-2.7.10
FSL/5.0.8-intel-2015B-Python-2.7.10
GPAW/0.9.0.8965-ictce-6.3.5-Python-2.7.6
GPAW/0.9.0.8965-ictce-7.1.2-Python-2.7.8
Greenlet/0.4.0-ictce-6.3.5-Python-2.7.6
Greenlet/0.4.0-ictce-7.1.2-Python-2.7.8
(D)
(D)
(D)
(D)
(D)
(D)
(D)
(D)
(D)
(D)
HTSeq/0.5.4p5-ictce-6.3.5-Python-2.7.6
IPython/1.1.0-ictce-7.1.2-Python-2.7.8
IPython/1.2.0-ictce-7.1.2-Python-2.7.8
IPython/2.1.0-ictce-7.1.2-Python-2.7.8
IPython/2.4.1-ictce-7.1.2-Python-2.7.8
IPython/3.1.0-ictce-7.1.2-Python-2.7.8
IPython/3.2.0-intel-2015B-Python-2.7.10
(D)
IPython/4.0.0-intel-2015B-Python-2.7.10-broken
Instant/1.3.0-ictce-6.3.5-Python-2.7.6
Instant/1.4.0-ictce-6.3.5-Python-2.7.6
Instant/1.4.0-ictce-7.1.2-Python-2.7.8
(D)
Jinja2/2.7.2-ictce-6.3.5-Python-2.7.6
Jinja2/2.7.2-ictce-7.1.2-Python-2.7.8
(D)
KmerGenie/1.6982-intel-2015B-Python-2.7.10
MACS/1.4.2-1-goolf-1.7.20-Python-2.7.10
MDP/3.3-ictce-6.3.5-Python-2.7.6
MDP/3.3-ictce-7.1.2-Python-2.7.8
(D)
Markdown/2.6.2-intel-2015B-Python-2.7.10
MarkupSafe/0.23-intel-2015B-Python-2.7.10
Mercurial/2.3.2-ictce-6.3.5-Python-2.7.6
Mesa/7.11.2-ictce-7.1.2-Python-2.7.8
Mesa/9.2.5-ictce-7.1.2-Python-2.7.8
Mesa/9.2.5-intel-2015B-Python-2.7.10
(D)
Metassembler/1.5-intel-2015B-Python-2.7.10
NEURON/7.2-ictce-6.3.5-Python-2.7.6
NEURON/7.3-ictce-6.3.5-Python-2.7.6
NEURON/7.3-ictce-7.1.2-Python-2.7.8
(D)
NWChem/6.5.revision26243-foss-2014c-2014-09-10-Python-2.7.8
NWChem/6.5.revision26243-ictce-7.1.2-2014-09-10-Python-2.7.8 (D)
Oger/1.1.3-ictce-6.3.5-Python-2.7.6
Oger/1.1.3-ictce-7.1.2-Python-2.7.8
(D)
OpenBabel/2.3.2-ictce-6.3.5-Python-2.7.6
OpenBabel/2.3.2-ictce-7.1.2-Python-2.7.8
OpenBabel/2.3.2-intel-2015B-Python-2.7.10-Eigen-2.0.17
OpenBabel/2.3.2-intel-2015B-Python-2.7.10
(D)
PETSc/3.5.1-intel-2014b-Python-2.7.8
PETSc/3.5.1-intel-2015A-Python-2.7.9
PETSc/3.5.3-goolf-1.7.20-Python-2.7.10
PETSc/3.5.3-intel-2015B-Python-2.7.10
(D)
PP/1.6.4-ictce-6.3.5-Python-2.7.6
PP/1.6.4-ictce-7.1.2-Python-2.7.8
(D)
PSI/4.0b5-intel-2015B-mt-maxam7-Python-2.7.10
PSI/4.0b6-20150814-intel-2015B-mt-maxam7-Python-2.7.10
(D)
Paste/2.0.2-intel-2015B-Python-2.7.10
PasteDeploy/1.5.2-intel-2015B-Python-2.7.10
PasteScript/1.6-intel-2015B-Python-2.7.10
PasteScript/2.0.2-intel-2015B-Python-2.7.10
(D)
PyQt/4.11.4-intel-2015B-Python-2.7.10
PyYAML/3.11-intel-2015B-Python-2.7.10
PyZMQ/2.2.0.1-ictce-6.3.5-Python-2.7.6-zmq2
PyZMQ/2.2.0.1-ictce-6.3.5-Python-2.7.6-zmq3
PyZMQ/14.6.0-intel-2015B-Python-2.7.10-zmq3
PyZMQ/14.7.0-intel-2015B-Python-2.7.10-zmq3
PyZMQ/14.7.0-intel-2015B-Python-2.7.10-zmq4
(D)
Pygments/2.0.2-intel-2015B-Python-2.7.10
Pylons/1.0.2-intel-2015B-Python-2.7.10
Python/2.7.3-ictce-7.1.2
Python/2.7.6-ictce-6.3.5
Python/2.7.6-ictce-7.1.2
Python/2.7.8-foss-2014c
Python/2.7.8-goolf-1.7.20
Python/2.7.8-ictce-7.1.2
Python/2.7.8-intel-2014b
Python/2.7.8-intel-2015a
Python/2.7.8-intel-2015B
Python/2.7.9-GCC-4.9.2-bare
Python/2.7.9-goolf-1.7.20
Python/2.7.9-intel-2015a-bare
Python/2.7.9-intel-2015A
Python/2.7.9-intel-2015B
Python/2.7.10-GCC-4.8.4-bare
Python/2.7.10-goolf-1.0.20
Python/2.7.10-goolf-1.7.20
Python/2.7.10-intel-2015B-bare
Python/2.7.10-intel-2015B
Python/3.3.2-ictce-6.3.5
Python/3.3.2-ictce-7.1.2
Python/3.4.3-intel-2015B
(D)
Qt/4.8.6-intel-2015B-Python-2.7.10
(D)
SCOOP/0.5.3-ictce-6.3.5-Python-2.7.6
SCons/2.3.0-ictce-6.3.5-Python-2.7.6
SCons/2.3.0-ictce-7.1.2-Python-2.7.8
SCons/2.3.5-intel-2015B-Python-2.7.10
(D)
SGA/0.10.13-goolf-1.7.20-Python-2.7.10
SGA/0.10.13-intel-2015B-Python-2.7.10
SIP/4.16.8-intel-2015B-Python-2.7.10
SWIG/2.0.4-ictce-6.3.5-Python-2.7.6
SWIG/3.0.0-ictce-6.3.5-Python-2.7.6
SWIG/3.0.2-ictce-6.3.5-Python-2.7.6
SWIG/3.0.2-ictce-7.1.2-Python-2.7.8
SWIG/3.0.2-intel-2014b-Python-2.7.8
SWIG/3.0.3-intel-2015a-Python-2.7.9
SWIG/3.0.6-goolf-1.7.20-Python-2.7.10
SWIG/3.0.6-intel-2015B-Python-2.7.10
SWIG/3.0.7-intel-2015B-Python-2.7.10
(D)
ScientificPython/2.8-ictce-6.3.5-Python-2.7.6
ScientificPython/2.8-ictce-7.1.2-Python-2.7.8
ScientificPython/2.8.1-ictce-6.3.5-Python-2.7.6
ScientificPython/2.8.1-intel-2014b-Python-2.7.8
ScientificPython/2.8.1-intel-2015A-Python-2.7.8
ScientificPython/2.8.1-intel-2015A-Python-2.7.9
ScientificPython/2.9.4-goolf-1.7.20-Python-2.7.10
ScientificPython/2.9.4-intel-2015A-Python-2.7.9
ScientificPython/2.9.4-intel-2015B-Python-2.7.10
(D)
Sphinx/1.2.2-ictce-6.3.5-Python-2.7.6
TAMkin/1.0.1-ictce-6.3.5-Python-2.7.6
Theano/0.6.0-ictce-6.3.5-Python-2.7.6
Theano/0.6.0-ictce-7.1.2-Python-2.7.8
(D)
ToscaWidgets/0.9.12-intel-2015B-Python-2.7.10
Trilinos/10.12.2-ictce-6.3.5-Python-2.7.6
TurboCheetah/1.0-intel-2015B-Python-2.7.10
TurboJson/1.3.2-intel-2015B-Python-2.7.10
UFC/2.2.0-ictce-6.3.5-Python-2.7.6
UFL/1.3.0-ictce-6.3.5-Python-2.7.6
UFL/1.4.0-ictce-6.3.5-Python-2.7.6
UFL/1.4.0-ictce-7.1.2-Python-2.7.8
(D)
Viper/1.0.1-ictce-6.3.5-Python-2.7.6
Viper/1.0.1-ictce-7.1.2-Python-2.7.8
(D)
VisIt/2.7.3-ictce-6.3.5-Python-2.7.6
dealii/8.2.1-intel-2015A-Python-2.7.9
dealii/8.2.1-intel-2015B-Python-2.7.10-test
dealii/8.2.1-intel-2015B-Python-2.7.10
(D)
freeglut/2.8.1-intel-2015B-Python-2.7.10
(D)
h5py/2.2.1-ictce-6.3.5-Python-2.7.6
libMesh/0.9.4-goolf-1.7.20-Python-2.7.10
libX11/1.6.3-goolf-1.7.20-Python-2.7.10
libX11/1.6.3-intel-2015B-Python-2.7.10
libX11/1.6.3-intel-2015B-Python-3.4.3
(D)
libXext/1.3.3-intel-2015B-Python-2.7.10
libXft/2.3.2-intel-2015B-libX11-1.6.3-Python-2.7.10
libXi/1.7.2-intel-2015B-Python-2.7.10
(D)
libXrender/0.9.9-intel-2015B-Python-2.7.10
libxcb/1.8-ictce-6.3.5-Python-2.7.6
libxcb/1.8-ictce-7.1.2-Python-2.7.6
libxcb/1.8-ictce-7.1.2-Python-2.7.8
libxcb/1.10-intel-2014b-Python-2.7.8
libxcb/1.11-goolf-1.0.20-Python-2.7.10
libxcb/1.11-goolf-1.7.20-Python-2.7.10
libxcb/1.11-intel-2015B-Python-2.7.10
libxcb/1.11-intel-2015B-Python-3.4.3
(D)
libxml2/2.9.2-goolf-1.7.20-Python-2.7.10
libxml2/2.9.2-ictce-7.1.2-Python-2.7.8
libxml2/2.9.2-intel-2015B-Python-2.7.10
lxml/3.4.2-intel-2015B-Python-2.7.10
lxml/3.4.4-intel-2015B-Python-2.7.10
(D)
matplotlib/1.2.1-intel-2015B-Python-2.7.10
matplotlib/1.3.1-ictce-6.3.5-Python-2.7.6
matplotlib/1.4.0-ictce-7.1.2-Python-2.7.8
matplotlib/1.4.3-intel-2015B-Python-2.7.10
molmod/1.0-ictce-6.3.5-Python-2.7.6
molmod/1.0-intel-2015B-Python-2.7.10
mpi4py/1.3-ictce-6.3.5-Python-2.7.6
mpi4py/1.3-ictce-7.1.2-Python-2.7.8
mpi4py/1.3.1-ictce-6.3.5-Python-2.7.6
netcdf4-python/1.0.7-intel-2015A-Python-2.7.9
networkx/1.10-intel-2015B-Python-2.7.10
numpy/1.7.1-ictce-7.1.2-Python-2.7.8
numpy/1.8.2-goolf-1.7.20-Python-2.7.10
numpy/1.8.2-intel-2015A-Python-2.7.9
numpy/1.8.2-intel-2015B-Python-2.7.10
pandas/0.11.0-ictce-6.3.5-Python-2.7.6
pandas/0.11.0-ictce-7.1.2-Python-2.7.8
pandas/0.16.2-intel-2015B-Python-2.7.10
paste.deploy/1.5.2-intel-2015B-Python-2.7.10
paste.script/1.6-intel-2015B-Python-2.7.10
paycheck/1.0.2-ictce-6.3.5-Python-2.7.6
paycheck/1.0.2-ictce-7.1.2-Python-2.7.8
phonopy/1.6.4-intel-2015B-Python-2.7.10
pysam/0.8.3-goolf-1.7.20-Python-2.7.10
pysam/0.8.3-intel-2015B-Python-2.7.10
pysqlite/2.6.3-ictce-7.1.2-Python-2.7.3
pysqlite/2.6.3-ictce-7.1.2-Python-2.7.6
pysqlite/2.6.3-ictce-7.1.2-Python-2.7.8
pysqlite/2.6.3-intel-2015A-Python-2.7.8
pysqlite/2.6.3-intel-2015B-Python-2.7.10
pysqlite/2.8.1-intel-2015B-Python-2.7.10
python-dateutil/2.1-ictce-6.3.5-Python-2.7.6
python-dateutil/2.1-ictce-7.1.2-Python-2.7.8
python-meep/1.4.2-ictce-6.3.5-Python-2.7.6
requests/2.7.0-ictce-7.1.2-Python-2.7.8
requests/2.7.0-intel-2015B-Python-2.7.10
scikit-learn/0.14.1-ictce-6.3.5-Python-2.7.6
setuptools/3.6-ictce-6.3.5-Python-2.7.6
setuptools/3.6-ictce-7.1.2-Python-2.7.8
simplejson/3.8.0-intel-2015B-Python-2.7.10
sympy/0.7.6-goolf-1.7.20-Python-2.7.10
sympy/0.7.6-intel-2015B-Python-2.7.10
traitlets/4.0.0-intel-2015B-Python-2.7.10
xcb-proto/1.7-ictce-6.3.5-Python-2.7.6
xcb-proto/1.7-ictce-7.1.2-Python-2.7.6
xcb-proto/1.7-ictce-7.1.2-Python-2.7.8
xcb-proto/1.10-ictce-6.3.5-Python-2.7.6
xcb-proto/1.10-ictce-7.1.2-Python-2.7.6
xcb-proto/1.10-intel-2014b-Python-2.7.8
xcb-proto/1.11-goolf-1.0.20-Python-2.7.10
xcb-proto/1.11-goolf-1.7.20-Python-2.7.10
(D)
(D)
(D)
(D)
(D)
(D)
(D)
(D)
(D)
(D)
(D)
(D)
xcb-proto/1.11-intel-2015B-Python-2.7.10
xcb-proto/1.11-intel-2015B-Python-3.4.3
yaff/1.0-ictce-6.3.5-Python-2.7.6
(D)
Where:
(D): Default Module
Use "module spider" to find all possible modules.
Use "module keyword key1 key2 ..." to search for all possible modules matching any of the "keys".
2.1.4 Module Avail Python
This command generates the same output as “Module Avail python”.
2.2 Command to Load a Python Module
[yangliu@ada4 ~]$ module load Python/2.7.10-intel-2015B
[yangliu@ada4 ~]$
2.3 Command to View the Loaded Python Module
[yangliu@ada4 ~]$ module list
Currently Loaded Modules:
1) GCC/4.8.4
9) bzip2/1.0.6-intel-2015B
2) icc/2015.3.187-GCC-4.8.4
10) zlib/1.2.8-intel-2015B
3) ifort/2015.3.187-GCC-4.8.4
11) libreadline/6.3-intel-2015B
4) iccifort/2015.3.187-GCC-4.8.4
12) ncurses/5.9-intel-2015B
5) impi/5.0.3.048-iccifort-2015.3.187-GCC-4.8.4 13) OpenSSL/1.0.1m-intel-2015B
6) iimpi/7.3.5-GCC-4.8.4
14) freetype/2.6-intel-2015B
7) imkl/11.2.3.187-iimpi-7.3.5-GCC-4.8.4
8) intel/2015B
15) libpng/1.6.18-intel-2015B
16) Python/2.7.10-intel-2015B
2.4 Command to Purge Python Module from Your Enviroment
[yangliu@ada4 ~]$ module purge
[yangliu@ada4 ~]$ module list
No modules loaded
3 Find the Python Version in Use
[yangliu@ada4 ~]$ python -V
Python 2.7.10
4 Find the Location of Python in Use
[yangliu@ada4 ~]$ which python
/software/tamusc/Python/2.7.10-intel-2015B/bin/python
5 Run Python Interpretor
[yangliu@ada4 ~]$ python
Python 2.7.10 (default, May 28 2015, 17:39:01)
[GCC Intel(R) C++ gcc 4.8 mode] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
6 Exit Python Interpretor
[yangliu@ada4 ~]$ python
Python 2.7.10 (default, May 28 2015, 17:39:01)
[GCC Intel(R) C++ gcc 4.8 mode] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
7 Interactive Execution of Python Statements
Reminder: you should run a python executor to execute python statements.
7.1 Print
7.1.1 Excution in Python 2
[yangliu@ada4 ~]$ module load Python/2.7.10-intel-2015B
[yangliu@ada4 ~]$ python
>>> print "hello, world"
hello, world
>>> quit()
7.1.2 Excution in Python 3
[yangliu@ada4 ~]$ module purge
[yangliu@ada4 ~]$ module load Python/3.4.3-intel-2015B
[yangliu@ada4 ~]$ python
Python 3.4.3 (default, Aug 24 2015, 17:31:22)
[GCC Intel(R) C++ gcc 4.8 mode] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello, world"
File "<stdin>", line 1
print "hello, world"
^
SyntaxError: Missing parentheses in call to 'print'
>>> print("hello, world")
hello, world
7.1.3 Exercises
(1) What is the difference for print between python 2 and python 3?
7.2 Division /
7.2.1 Excution in Python 2
[yangliu@ada4 ~]$ module load Python/2.7.10-intel-2015B
[yangliu@ada4 ~]$ 5/2
-bash: 5/2: No such file or directory
[yangliu@ada4 ~]$ python
Python 2.7.10 (default, May 28 2015, 17:39:01)
[GCC Intel(R) C++ gcc 4.8 mode] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 5/2
2
>>> from __future__ import division
>>> 5/2
2.5
>>> del division
>>> 5/2
2.5
>>> 5*1.0/2
2.5
(7.2.3) Try / with Python 3
7.2.3 Exercises
(1) What does “from __future__ import division” do?
(2) What is the difference for the divions operation (/) between python 2 and python 3?
7.3 If
7.3.1 Try the following Statements using Python 2
>>> x = raw_input("Plese enter an integer: ")
Plese enter an integer: -5
>>> if x < 0:
...
print "x is negative"
... else:
...
print "x is not negative"
...
x is not negative
>>> x = int(raw_input("Plese enter an integer: "))
Plese enter an integer: -5
>>> if x < 0:
...
print "x is negative"
... else:
...
print "x is not negative"
...
x is negative
7.3.2 Exercises
(1) What is the purpose of 'int(raw_input("Plese enter an integer: "))'?
(2) What does the “...” mean during the execution of the statements?
(3) Write a program which asks a user to enter an integer, and then prints a message to tell the user that
the integer is even or odd.
7.4 While
7.4.1 Try the following Statements using Python 2
>>> x = 1
>>> s = 0
>>> while x != 0:
...
x = int(raw_input("Please enter an integer: "))
...
if x < 0:
...
continue
...
s += x
...
print "s = ", s
...
Please enter an integer: 5
s= 5
Please enter an integer: 10
s = 15
Please enter an integer: 20
s = 35
Please enter an integer: -10
Please enter an integer: 30
s = 65
7.4.2 Exercises
(1) What does the program do?
(2) What is the purpose of “continue”?
(3) Rewrite the program without using “continue”
7.5 For
7.5.1 Try the following Statements using Python 2
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> for i in range(10):
...
print i**2
...
0
1
4
9
16
25
36
49
64
81
7.5.2 Exercises
(1) What is the purpose of operator “**”?
(2) Modify the program to sum the odd number in the range of 1000.
8 Execution of Python Scripts
8.1 Python Name_of_Script
(1) Write a file with contents below:
x=1
s=0
while x != 0:
x = int(raw_input("Please enter an integer: "))
if x < 0:
continue
s += x
print "s = ", sll
(2) Save the file as sum_positive_integers.py
(3)Execute the file using Python
[yangliu@ada4 Python]$ python while.py
8.2 Executable Script
(1) Add the line below in the beginning of sum_positive_integers.py and save the file
#!/software/easybuild/software/Python/2.7.10-intel-2015B/bin/python
(2) Change the mode of sum_positive_integers.py to be executable.
[yangliu@ada4 Python]$ chmod +x sum_positive_integers.py
(3)Run the executable script
[yangliu@ada4 Python]$ ./sum_positive_integers.py
(4) Purge the current module and Run the program again (An Error occurs)
[yangliu@ada4 Python]$ module purge
[yangliu@ada4 Python]$ ./sum_positive_integers.py
/software/easybuild/software/Python/2.7.10-intel-2015B/bin/python: error while loading shared
libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
Related documents