Lab 01
Lab 01
Introduction to Python
Background
www.python.org
http://www.python.org/download/releases/2.7/
https://www.jetbrains.com/pycharm/
Math in Python
>>> 1 + 1
>>> 6-5
>>> 2*5
10
>>> 5**2
25
>>> 21/3
7
>>> 23%3
Python Operators
+ Addition 4+5 9
- Subtraction 8-5 3
* Multiplication 4*5 20
/ Division 19/3 6
% Remainder 19%3 5
** Exponent 2**4 16
Order of Operations:
• parentheses ()
• exponents **
• multiplication *, division \, and remainder %
• addition + and subtraction -
Comments in Python:
Variables:
v=1
print "The value of v is now", v
v=v+1
print "to make v five times bigger, you would have to type v = v * 5"
v=v*5
Strings:
word1 = "Good"
word2 = "Morning"
print sentence
Boolean operators:
Expression Function
!= not equal to
== equal to
Conditional Statements:
‘if' - Statement
y=1
if y == 1:
a=1
if a > 5:
else:
‘elif' - Statement
z=4
if z > 70:
elif z < 7:
Example
Obtaining data from the user