Boston Python Workshop 8/Friday/Tutorial: Difference between revisions

no edit summary
imported>Jesstess
No edit summary
imported>Jesstess
No edit summary
Line 224:
<pre>
name = "Jessica"
print "Hello " + name
</pre>
 
===Printing===
 
You can print strings using the <code>print</code> function:
 
<pre>
h = "Hello"
w = "World"
print (h + w)
</pre>
 
<pre>
my_string = "Alpha " + "Beta " + "Gamma " + "Delta"
print (my_string)
</pre>
 
Line 245:
 
<pre>
print ("Hello" + 1)
</pre>
 
Hey now! The output from the previous example was really different and interesting; let's break down exactly what happened:
 
<code>>>> print ("Hello" + 1)</code><br />
<code>Traceback (most recent call last):</code><br />
<code> File "<stdin>", line 1, in <module></code><br />
Line 266:
 
<pre>
print ("Hello" + "World")
</pre>
 
Line 274:
 
<pre>
print ("Hello" + 1)
</pre>
 
Line 282:
 
<pre>
print ("Hello" + str(1))
</pre>
 
Line 292:
 
<pre>
print (len("Hello"))
print (len(""))
fish = "humuhumunukunukuapuaʻa"
length = str(len(fish))
print (fish + " is a Hawaiian fish whose name is " + length + " characters long.")
</pre>
 
Line 304:
 
<pre>
print ('Hello')
print ("Hello")
</pre>
 
Line 313:
 
<pre>
print ('I'm a happy camper')
</pre>
 
Line 325:
 
<pre>
print ("I'm a happy camper")
</pre>
 
Line 331:
 
<pre>
print ("A" * 40)
print ("ABC" * 12)
h = "Happy"
b = "Birthday"
print ((h + b) * 10)
</pre>
 
Line 347:
<pre>
total = 1.5 - 1/2
print (total)
print(type(total))
</pre>
 
Line 356:
b = "brown"
c = "fox jumps over the lazy dog"
print ("The " + a * 3 + " " + b * 3 + " " + c)
</pre>
 
Line 491:
<pre>
if 6 > 5:
print ("Six is greater than five!")
</pre>
 
Line 506:
Enter 4 spaces, and then type
 
<code> print ("Six is greater than five!")</code>
 
Press Enter to end the line, and press Enter again to tell Python you are done with this code block. All together, it will look like this:
Line 512:
<pre>
>>> if 6 > 5:
... print ("Six is greater than five!")
...
Six is greater than five!
Line 523:
<pre>
if 0 > 2:
print ("Zero is greater than two!")
</pre>
 
<pre>
if "banana" in "bananarama":
print ("I miss the 80s.")
</pre>
 
Line 539:
brother_age = 12
if sister_age > brother_age:
print ("sister is older")
else:
print ("brother is older")
</pre>
 
Line 573:
temperature = 32
if temperature > 60 and temperature < 75:
print ("It's nice and cozy in here!")
else:
print ("Too extreme for me.")
</pre>
 
Line 581:
hour = 11
if hour < 7 or hour > 23:
print ("Go away!")
print ("I'm sleeping!")
else:
print ("Welcome to the cheese shop!")
print ("Can I interest you in some choice gouda?")
</pre>
 
Line 598:
brother_age = 12
if sister_age > brother_age:
print ("sister is older")
elif sister_age == brother_age:
print ("sister and brother are the same age")
else:
print ("brother is older")
</pre>
 
Line 610:
color = "orange"
if color == "green" or color == "red":
print ("Christmas color!")
elif color == "black" or color == "orange":
print ("Halloween color!")
elif color == "pink":
print ("Valentine's Day color!")
</pre>
 
Anonymous user