Download presentation
Presentation is loading. Please wait.
Published byBritton Montgomery Modified over 9 years ago
1
Python 2 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1
2
Libraries A library is a collection of useful functions that are pre-written. Add the functionality of a library with the import statement. Import statement can come anywhere (but not a good idea in a loop) Ex: import math print math.pow(2,3) 2
3
Libraries http://docs.python.org/library/math.html Most useful library is the math library Call with name of library, a decimal point and the name of the function within the library 3
4
Libraries Ex: math.tan(1) returns the tangent of 1 Ex: math.pi returns the value of pi to the available accuracy 4
5
For loop For loop - loop will execute a definite amount of times Ex: for i in [1, 2, 3, 4]: print "i=", i Ex: for x in range(9): print "loop" 5
6
For loops Ex: for a in range(1,6): print "one" print "a = ", a, " and big one = ", a**3 Test = a * 1.5 print "Test = ", Test DO: Example 2A 6
7
For loops Ex: for a in range(5): print "a = ", a for b in [10, 20, 30]: print "b = ", b 7
8
For loops Ex: for a in range(5): print "a = ", a for b in [10, 20, 30]: print "b = ", b for c in ["stop", "go"]: print c Notice the indenting! 8
9
For loops Ex: for a in range(2, 5): print "a = ", a print a Results in a syntax error because of indenting – amount of indenting is not important but you MUST be consistent DO: Example 2B 9
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.