Boston Python Workshop 8/Friday/Tutorial: Difference between revisions
Content added Content deleted
imported>Jesstess |
imported>Jesstess |
||
Line 511:
====if statements====
The simplest way to make a choice in Python is with the <code>if</code> keyword. Here's an example (don't try to type this one, just look at it for now):
<code>if 6 > 5:</code><br />
</pre>▼
That
<ol>
<li>First, type the<br />
<br />
<code>if 6 > 5:</code><br />
<br />
part, and press 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.</li>▼
<li>Press the spacebar 4 times to indent.</li>
<li>Type<br />
<br />
<code>print("Six is greater than five!")</code><br /><br /></li>
<li>Press Enter to end the line. The prompt will still be a <code>...</code></li>
<li>Press Enter
All together, it will look like this:
▲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.
▲<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:
<pre>
|