Python files: Difference between revisions

no edit summary
imported>Jesstess
(Created page with " == Goal #1: practice reading and running Python files == (Estimated completion time: 15 - 30 minutes) We'll be practicing two skills with this goal. The first is <b>reading...")
 
imported>Jesstess
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1:
[[File:Treasure_map.png|100px]]
 
(Estimated completion time: 15 - 30 minutes)
 
== Goal #1: practice reading and running Python files ==
 
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!
(Estimated completion time: 15 - 30 minutes)
 
<ol>
<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 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 Desktop directory. See [[Boston Python Workshop 8/Friday#Goal_.234:_practice_navigating_the_computer_from_a_terminal|navigating from a terminal]] for a refresher on those commands.</li>
<li>Once you are in your Desktop directory, execute the contents of <code>nobel.py</code> by typing
 
<pre>
python nobel.py
</pre>
 
at the terminal prompt.
 
<code>nobel.py</code> introduces two new concepts: comments and multiline strings.</li>
 
<li>Open <code>nobel.py</code> in your text editor (see [[Boston Python Workshop 8/Friday#Goal_.232:_prepare_a_text_editor|preparing your text editor]] for a refresher on starting the editor).</li>
<li>Read through the file in your text editor carefully and check your understanding of both the comments and the code.</li>
</ol>
 
Study the script until you can answer these questions:
<ol>
<li>How do you comment code in Python?</li>
<li>How do you print just a newline?</li>
<li>How do you print a multi-line string so that whitespace is preserved?</li>
</ol>
 
 
== Goal #2: more practice with Python files ==
We'll be practicing two skills with this goal. The first is <b>reading and understanding Python programs</b>. The second is <b>running these programs from the terminal</b>.
 
For each of the following Python programs (folks often call these "scripts"), please do the following:
Line 26 ⟶ 54:
<b>Here are you scripts to read and run</b>. Have fun with them!
 
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit1/nobel.py nobel.py] (this is the script we analyzed in the video)
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit1/tip_calculator.py tip_calculator.py]
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit1/pizza_calculator.py pizza_calculator.py]
Anonymous user