If you haven't already, please complete the short setup instructions at: http://bit.ly/intro-setup
In [ ]:
Please also visit: http://codeacademy.com
and create an account.
After completing these steps, you should:
Raise your hand (or place a yellow sticky note on your screen), if you need help.
Terminal and start python
In [ ]:
2 + 2
In [ ]:
1.4 + 2.25
In [ ]:
4 - 2
In [ ]:
2 * 3
In [ ]:
4 / 2
In [ ]:
1 / 2
Whole number 1 divided by whole number 2
In [ ]:
1.0 / 2
In [ ]:
2 + 2
In [ ]:
2+2
In [ ]:
(1 + 3) * 4
In [ ]:
x = 4
In [ ]:
x * 3
Variables
In [ ]:
cups_of_flour = 5
In [ ]:
cups_of_flour * .5
In [ ]:
1 / 2
In [ ]:
1.0 / 2
Two different data types
Let's use a function
In [ ]:
type(1)
In [ ]:
type(1.0)
Questions?
String data type
In [ ]:
"Hello"
In [ ]:
"Python, I'm your #1 fan!"
In [ ]:
type("Hello")
In [ ]:
name = "Carol"
In [ ]:
2 + 2
In [ ]:
"Carol" + "Willing"
In [ ]:
"Carol " + "Willing"
In [ ]:
"Carol" + " " + "Willing"
In [ ]:
name = "Carol"
In [ ]:
"My name is " + name
Tip - arrow up save typing
In [ ]:
"Hello" + 1
In [ ]:
"Hello" + "1"
In [ ]:
type(1)
In [ ]:
type("1")
In [ ]:
"Hello" + str(1)
In [ ]:
len("Hello")
In [ ]:
len(name)
In [ ]:
"The length of my name is " + str(len(name))
In [ ]:
"Hello"
In [ ]:
'Hello'
In [ ]:
"Python, I'm your #1 fan!"
In [ ]:
"A" * 40
In [ ]:
h = "Happy"
In [ ]:
b = "Birthday"
In [ ]:
(h + b) * 10
Printing - interactive vs file
In [ ]:
"Hello"
In [ ]:
print("Hello")
Questions?
In [ ]:
3 ** 3
In [ ]:
type(1)
In [ ]:
type(1.0)
In [ ]:
type("1")
Make choices
In [ ]:
True
In [ ]:
False
In [ ]:
type(True)
In [ ]:
type(False)
In [ ]:
0 == 0
In [ ]:
0 == 1
In [ ]:
0 != 1
In [ ]:
"a" == "A"
In [ ]:
1 > 0
In [ ]:
2 >= 3
In [ ]:
-1<0
In [ ]:
.5 <= 1
In [ ]:
"H" in "Hello"
In [ ]:
"x" in "Hello"
In [ ]:
"a" not in "abcde"
In [ ]:
type(True)
In [ ]:
type("True")
In [ ]:
type(true)
In [ ]:
x = 4
In [ ]:
x == 4
In [ ]:
if 6 > 5:
print("Six is greater than 5")
In [ ]:
if 0 > 2:
print("Zero is greater")
In [ ]:
if "banana" in "bananarama":
print("I miss the 80s")
One of two actions
In [ ]:
sister = 15
In [ ]:
brother = 12
In [ ]:
if sister > brother:
print("Sister is older")
else:
print("Brother is older")
In [ ]:
1 > 0 and 1 < 2
In [ ]:
1 < 2 and "x" in "abc"
In [ ]:
"a" in "abc" and "b" in "abc" and "c" in "abc"
In [ ]:
"a" in "hello" or "e" in "hello"
In [ ]:
temp = 32
In [ ]:
if temp > 60 and temp < 75:
print("Nice and cozy")
else:
print("Too extreme for me")
One of three things
In [ ]:
sister = 15
brother = 15
In [ ]:
if sister > brother:
print("Sister is older")
elif sister == brother:
print("Twinsies!!")
else:
print("Brother is older")
Questions? 47 min mark
Practice problems - Codeacademy practice Strings and choices http://bit.ly/py-practice
In [4]:
from IPython.display import YouTubeVideo
# a tutorial about Python at PyCon 2014 in Montreal, Canada by Jessica McKellar
# Credit: William Stein.
YouTubeVideo('MirG-vJOg04')
Out[4]:
In [6]:
from IPython.display import IFrame
# Pull in the tutorial prep information from OpenHatch wiki
IFrame('http://bit.ly/intro-setup', width='100%', height=350)
Out[6]:
In [ ]: