Boston Python workshop 2/Friday tutorial: Difference between revisions

Content added Content deleted
imported>Jesstess
No edit summary
imported>Jesstess
No edit summary
Line 324: Line 324:
the code.
the code.


Practice
==Practice==


Read the following expressions, but don't execute them. Guess what the output
Read the following expressions, but don't execute them. Guess what the output will be. After you've made a guess, copy and paste the expressions at a Python prompt and check your guess.
will be. After you've made a guess, copy and paste the expressions at a Python
prompt and check your guess.


1.
1.
<pre>
total = 1.5 - 1/2 + ((-2.0/2) - (1.0/2))
total = 1.5 - 1/2 + ((-2.0/2) - (1.0/2))
print total
print total
type(total)
type(total)
</pre>


2.
2.
<pre>
a = "quick"
a = "quick"
b = "brown"
b = "brown"
c = "fox jumps over the lazy dog"
c = "fox jumps over the lazy dog"
print "The", a * 3, b * 3, c
print "The", a * 3, b * 3, c
</pre>


3.
3.
<pre>
print 2.0 * 123, "2.0" * 123
print 2.0 * 123, "2.0" * 123
print 2.0 * 123 + str(2.0) * 123
print 2.0 * 123 + str(2.0) * 123
</pre>


4.
4.
<pre>
a = "| (_| -()- -()- -()- -()- | -()- -()- -()- -()- ||\n"
a = "| (_| -()- -()- -()- -()- | -()- -()- -()- -()- ||\n"
b = "|_\_|_/___|__|__|__|___|__|___|__|___________________________||\n"
b = "|_\_|_/___|__|__|__|___|__|___|__|___________________________||\n"
Line 360: Line 365:


print d + f + i + e + b + g + a + c + l + h + j + k
print d + f + i + e + b + g + a + c + l + h + j + k
</pre>