Computational Physics Python Programming
Python Programming
Computational Physics Python Programming
Outline
Useful Programming Tools
? Conditional Execution ? Loops ? 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.
Start
Is X < 0 ?
True
Conditional Execution is done with if statements.
if some_logical_condition : statements_to_execute_if_true statements_are_indented
if ends with end of indentation ... no special symbols or words
False
X = -X
Execute Conditional
Code
Ready for More Fun
if...elif...else statement example
## eenntteerr aa vvaaluluee ttoo tteesstt XX == ininppuutt(('E'EnntteerrVVaaluluee ooff XX:: ')')
If X is less than 0 we do this
## nnooww wwee ddoo tthhee tteesstt wwitithh ifif ssttaatteemmeenntt ifif XX --22::
pprrinintt 'X'X > --22 !'!' eellssee::
pprrinintt 'X'X isis nnoott bbeettwweeeenn --22 aanndd 00..' '
Otherwise, if X doesn't Match any of above, CTohnednitiwonecdaon tbheisa.ny
Logical Statement
Loops
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.
For iterating_var in sequence: statements
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
- lists carnegie mellon university
- 2d array exercise villanova
- solution to homework 2 university of texas at
- lecture 16 cornell university
- solutions to exercises ucl
- basic plotting with python and matplotlib
- topics in parallel and distributed computing
- two dimensional arrays
- computational physics python programming
- python for data science cheat sheet lists
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