Anonymous user
Boston Python Workshop 7/Friday/Tutorial: Difference between revisions
Boston Python Workshop 7/Friday/Tutorial (view source)
Revision as of 18:22, 2 November 2012
, 11 years ago→if statements
imported>Jesstess |
imported>Jesstess |
||
Line 502:
</pre>
That was our first multi-line piece of code, and the way to enter it at a Python prompt is a little different. First, type the
<code>if 6 > 5:</code>
Enter 4 spaces, and then type <code>print "Six is greater than five!"</code>. Hit enter to end the line, and hit enter again to tell Python you are done with this code block. All together, it will look like this:▼
part, and hit enter. The next line will have
<code>...</code>
as a prompt, instead of the usual <code>>>></code>. This is Python telling us that we are in the middle of a <b>code block</b>, and so long as we indent our code it should be a part of this code block.
Enter 4 spaces, and then type
<code>print "Six is greater than five!"</code>
▲
<pre>
Line 513 ⟶ 525:
</pre>
In this case, because 6 really is greater than 5, Python executes the code block under the if statement, and we see "Six is greater than five!" printed to the screen. Guess what will happen with these other expressions, then type them out and see if your guess was correct:
|