Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
DS4UX (Spring 2016)/Day 1 tutorial
(section)
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Python scripts== [[File:Treasure_map.png|100px]] 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> <li>Download the file http://mako.cc/teaching/2014/cdsw/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 [[DS4UX_(Spring_2016)/Day_1_exercise#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 python nobel.py 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 [[DS4UX_(Spring_2016)/Day_1_exercise#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>
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information