Computational Physics Python Programming
Python Programming
Computational Physics
Python Programming
Outline
¡ñ
¡ñ
Useful Programming Tools
¨C
Conditional Execution
¨C
Loops
¨C
Input/Output
Python Scripts, Modules, and Packages
Conditional Execution
¡ñ
¡ñ
Sometimes we only
want to execute a
segment of our program
when a certain condition
occurs.
Conditional Execution is
done with if statements.
Start
Is X < 0 ?
True
False
X = -X
Execute
Conditional
Code
if some_logical_condition :
statements_to_execute_if_true
statements_are_indented
if ends with end of indentation ...
no special symbols or words
Ready for More Fun
if...elif...else statement example
#
# enter
enter aa value
value to
to test
test
XX == input('Enter
input('EnterValue
Value of
of X:
X: ')')
#
# now
now we
we do
do the
the test
test with
with ifif statement
statement
ifif XX -2:
-2:
print
print 'X
'X > -2
-2 !'!'
else:
else:
print
print 'X
'X isis not
not between
between -2
-2 and
and 0.'
0.'
If X is less than 0
we do this
Otherwise, if X is
equal
To 0 we do this.
== means ¡°is equal to¡±
Otherwise, if X is
equal
To 1 we do this.
Otherwise, if X doesn't
Match any of above,
Condition
be any
Then we can
do this.
Logical Statement
Loops
¡ñ
¡ñ
¡ñ
¡ñ
For iterating_var in sequence:
statements
Loops are a special type
of conditional execution.
Loops iterate over a
sequence of items.
In python, the items can
be any items in a list.
We will often iterate
through the indices that
point to items in NumPy
arrays.
Item from
sequence
No More Items
In the Sequence
Next Item
Execute
Statement(s)
on Item
Ready for More Fun
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- how to pass data into and out of a loop
- python arrays university of babylon
- high performance computing in python using
- programming for gcse topic 6 1 lists arrays and
- python nump and park
- basic python programming for loops and reading
- computational physics python programming
- loops in python
- a beginners guide to arrays and do loops
Related searches
- python programming books free pdf
- best python programming book
- python programming language pdf book
- free python programming books
- python programming pdf free download
- python programming tutorials
- python programming for absolute beginners
- python programming on win32 download
- basic python programming examples
- python programming examples pdf
- python programming examples source code
- introduction to python programming pdf