Python Chapter 7 Notes
Mathematical Order of Nature, Fall 2009
http://grace.evergreen.edu/ins
08/25/17 Be sure to hit
refresh
on your browser to get the latest version.
Decisions, Section 7.1 - 7.3
The multi-way decision structure (section 7.3) is usually the best to use - make it your first choice until you see a better way.
The convert2 (p202) warning program but with multi-way decisions
A grading program grades.py (Ch2p2)
Comparisons, Section 7.1
The comparison operators (p203) <, <=, > >=, ==, !=.
The True and False values as results of comparison operations.
Strings are compared lexicographically. The underlying ASCII number determines the order (along with the usual dictionary rules for ordering).
One-way Decisions, Section 7.1
Sometimes handy, but don't use unless they fit.
The add-on situation, overtime.py
The over-writing situation, max3.py (p222), maxn.py (p223)
The search and quit situation, find.py
The Python program as module idiom (p205-206)
if __name__ == '__main__': main()
Exception Handling, Section 7.4
Use exceptions to check and report user input errors
except ValueError:
except NameError:
except Typeerror:
except SyntaxError:
except:
Fibonacci
Ch3p16 fib program
Ch6p7 fib function
fib recursion