|
|
Line 325: |
Line 325: |
|
<li>Read through the file in your text editor carefully and check your understanding of both the comments and the code.</li> |
|
<li>Read through the file in your text editor carefully and check your understanding of both the comments and the code.</li> |
|
</ol> |
|
</ol> |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
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. |
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
total = 1.5 - 1/2 + ((-2.0/2) - (1.0/2)) |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
c = "fox jumps over the lazy dog" |
|
⚫ |
print "The", a * 3, b * 3, c |
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
print 2.0 * 123, "2.0" * 123 |
|
⚫ |
print 2.0 * 123 + str(2.0) * 123 |
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
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 |
|
⚫ |
|
|
|
|
|
|
==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== |
|
==Booleans== |
Line 496: |
Line 545: |
|
</pre> |
|
</pre> |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
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. |
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
total = 1.5 - 1/2 + ((-2.0/2) - (1.0/2)) |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
c = "fox jumps over the lazy dog" |
|
⚫ |
print "The", a * 3, b * 3, c |
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
print 2.0 * 123, "2.0" * 123 |
|
⚫ |
print 2.0 * 123 + str(2.0) * 123 |
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
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 |
|
⚫ |
|
|
|
|
|
|
|
[[Boston Python workshop 2/Friday setup|« Back to the Friday setup page]] |
|
[[Boston Python workshop 2/Friday setup|« Back to the Friday setup page]] |