Boston Python Workshop 8/Friday/Tutorial: Difference between revisions
Content added Content deleted
imported>Jesstess |
imported>Jesstess |
||
Line 511: | Line 511: | ||
====if statements==== |
====if statements==== |
||
The simplest way to make a choice in Python is with the <code>if</code> keyword. Here's an example: |
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> |
|||
⚫ | |||
if 6 > 5: |
|||
print("Six is greater than five!") |
|||
⚫ | |||
That |
That is our first multi-line piece of code, and the way to type it at a Python prompt is a little different. Let's break down how to do this (type this out step by step): |
||
<ol> |
|||
<code> if 6 > 5:</code> |
|||
<li>First, type the<br /> |
|||
<br /> |
|||
<code>if 6 > 5:</code><br /> |
|||
<br /> |
|||
⚫ | |||
<li>Press the spacebar 4 times to indent.</li> |
|||
part, and press Enter. The next line will have |
|||
<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> |
|||
⚫ | |||
⚫ | |||
All together, it will look like this: |
|||
<code> ...</code> |
|||
⚫ | |||
Enter 4 spaces, and then type |
|||
⚫ | |||
⚫ | |||
<pre> |
<pre> |