Anonymous user
Boston Python workshop 2/Friday tutorial: Difference between revisions
Boston Python workshop 2/Friday tutorial (view source)
Revision as of 01:38, 27 May 2011
, 13 years agono edit summary
No edit summary |
|||
Line 325:
<li>Read through the file in your text editor carefully and check your understanding of both the comments and the code.</li>
</ol>
==Part 1 Practice==▼
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.▼
1.▼
<pre>▼
total = 1.5 - 1/2 + ((-2.0/2) - (1.0/2))▼
print total▼
type(total)▼
</pre>▼
2.▼
<pre>▼
a = "quick"▼
b = "brown"▼
c = "fox jumps over the lazy dog"▼
print "The", a * 3, b * 3, c▼
</pre>▼
3.▼
<pre>▼
print 2.0 * 123, "2.0" * 123▼
print 2.0 * 123 + str(2.0) * 123▼
</pre>▼
4.▼
<pre>▼
a = "| (_| -()- -()- -()- -()- | -()- -()- -()- -()- ||\n"▼
b = "|_\_|_/___|__|__|__|___|__|___|__|___________________________||\n"▼
c = "|________________________________|__|__()_|__()_|__()__|_____||\n"▼
d = " ___|)_______________________________________________________\n"▼
e = "|_/(|,\____/_|___/_|____/_|______|___________________________||\n"▼
f = "|___/____________________________|___________________________||\n"▼
g = "| | | () | () | () | | ||\n"▼
h = "|__\___|.________________________|___\_|___\_|___\_|___|_____||\n"▼
i = "|__/|_______/|____/|_____/|______|___________________________||\n"▼
j = "|_____/__________________________|____\|____\|____\|_________||\n"▼
k = "|____/___________________________|___________________________||\n"▼
l = "|__/___\_._______________________|__|__|__|__|__|__|___|_____||\n"▼
print d + f + i + e + b + g + a + c + l + h + j + k▼
</pre>▼
==End of Part 1===
Congratulations! You've learned about and practiced math, strings, variables, data types, exceptions, tracebacks, and executing Python from the Python prompt and from a file.
Take a break, stretch, meet some neighbors, and ask the staff if you have any questions about this material.
==Booleans==
Line 496 ⟶ 545:
</pre>
▲==Practice==
▲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.
▲1.
▲<pre>
▲total = 1.5 - 1/2 + ((-2.0/2) - (1.0/2))
▲print total
▲type(total)
▲</pre>
▲2.
▲<pre>
▲a = "quick"
▲b = "brown"
▲c = "fox jumps over the lazy dog"
▲print "The", a * 3, b * 3, c
▲</pre>
▲3.
▲<pre>
▲print 2.0 * 123, "2.0" * 123
▲print 2.0 * 123 + str(2.0) * 123
▲</pre>
▲4.
▲<pre>
▲a = "| (_| -()- -()- -()- -()- | -()- -()- -()- -()- ||\n"
▲b = "|_\_|_/___|__|__|__|___|__|___|__|___________________________||\n"
▲c = "|________________________________|__|__()_|__()_|__()__|_____||\n"
▲d = " ___|)_______________________________________________________\n"
▲e = "|_/(|,\____/_|___/_|____/_|______|___________________________||\n"
▲f = "|___/____________________________|___________________________||\n"
▲g = "| | | () | () | () | | ||\n"
▲h = "|__\___|.________________________|___\_|___\_|___\_|___|_____||\n"
▲i = "|__/|_______/|____/|_____/|______|___________________________||\n"
▲j = "|_____/__________________________|____\|____\|____\|_________||\n"
▲k = "|____/___________________________|___________________________||\n"
▲l = "|__/___\_._______________________|__|__|__|__|__|__|___|_____||\n"
▲print d + f + i + e + b + g + a + c + l + h + j + k
▲</pre>
[[Boston Python workshop 2/Friday setup|« Back to the Friday setup page]]
|