Boston Python Workshop 8/Friday/Tutorial: Difference between revisions

Content added Content deleted
imported>Jesstess
No edit summary
imported>Jesstess
No edit summary
Line 377: Line 377:
The string manipulate is exactly the same as before. The only difference is that you need to use <b>print</b> to print results to the screen:
The string manipulate is exactly the same as before. The only difference is that you need to use <b>print</b> to print results to the screen:


<code> h + w</code>
<code>h + w</code>


becomes
becomes


<code> print(h + w)</code>
<code>print(h + w)</code>


We'll see more examples of the print function in the next section.
We'll see more examples of the print function in the next section.
Line 389: Line 389:
[[File:Treasure_map.png|100px]]
[[File:Treasure_map.png|100px]]


Until now we've been executing commands at the Python prompt. This is great for math, short bits of code, and testing. For longer ideas, it's easier to store the code in a file.
Until now we've been using the interactive Python interpreter. This is great for learning and experimenting, but you can't easily save or edit your work. For bigger projects, we'll write our Python code in a file. Let's get some practice with this!


<ol>
<ol>
<li>Download the file http://mit.edu/jesstess/www/BostonPythonWorkshop7/nobel.py by right-clicking on it and saying to save it as a ".py" file to your Desktop. The ".py" extension hints that this is a Python script.</li>
<li>Download the file http://mit.edu/jesstess/www/BostonPythonWorkshop8/nobel.py by right-clicking on it and saying to save it as a ".py" file to your Desktop. The ".py" extension hints that this is a Python script.</li>
<li>Open a command prompt, and use the navigation commands (<code>dir</code> and <code>cd</code> on Windows, <code>ls</code>, <code>pwd</code>, and <code>cd</code> on OS X and Linux) to navigate to your home directory. See [[Boston Python Workshop 8/Friday#Goal_.234:_practice_navigating_the_computer_from_a_command_prompt|navigating from a command prompt]] for a refresher on those commands.</li>
<li>Open a terminal prompt, and use the navigation commands (<code>dir</code> and <code>cd</code> on Windows, <code>ls</code>, <code>pwd</code>, and <code>cd</code> on OS X and Linux) to navigate to your home directory. See [[Boston Python Workshop 8/Friday#Goal_.234:_practice_navigating_the_computer_from_a_command_prompt|navigating from a command prompt]] for a refresher on those commands.</li>
<li>Once you are in your home directory, execute the contents of <code>nobel.py</code> by typing
<li>Once you are in your Desktop directory, execute the contents of <code>nobel.py</code> by typing


<pre>
<pre>
Line 400: Line 400:
</pre>
</pre>


at a command prompt.
at the terminal prompt.


<code>nobel.py</code> introduces two new concepts: comments and multiline strings.</li>
<code>nobel.py</code> introduces two new concepts: comments and multiline strings.</li>