Skillshare intro to Python/Unit 4: Difference between revisions

From OpenHatch wiki
Content added Content deleted
imported>Jesstess
imported>Jesstess
No edit summary
Line 1: Line 1:
== Goal #1: using modules ==
== Goal #1: using modules ==


To get some more practice with the <code>random</code> module, we're going to read, run, and extend some Python scripts that use this module.
foo

For each of the following Python scripts, please do the following:

<ol>
<li>Download the script and save it to your Desktop. Be sure to save it as a <code>.py</code> file.</li>
<li>Open the script in your text editor.</li>
<li>Read through the script. Answer these questions:

<ul>
<li>Overall, what does this script do?</li>
<li>What variables and data types are used? Where are the strings, integers, and floats?</li>
<li>What functions from the <code>random</code> module are used, and why?</li>
<li>Where are the comments, and what do they tell you?</li>
</ul>
</li>
<li>Once you have a good sense of what the script does, open a terminal, navigate to the directory where you saved the script, and run it. Does it do what you expected?</li>
</ol>

<b>Here are you scripts to read and run</b>. Have fun with them!

* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit4/die.py nobel.py]
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit4/password_generator password_generator.py]

For <code>die.py</code>, how would you change the program to simulate rolling 2 dices?

For <code>password_generator.py</code>, how would you generate a password that was, instead of a fixed 10 characters long, a random length between 10 and 14 characters?



==Success!==
==Success!==

Revision as of 06:44, 13 June 2013

Goal #1: using modules

To get some more practice with the random module, we're going to read, run, and extend some Python scripts that use this module.

For each of the following Python scripts, please do the following:

  1. Download the script and save it to your Desktop. Be sure to save it as a .py file.
  2. Open the script in your text editor.
  3. Read through the script. Answer these questions:
    • Overall, what does this script do?
    • What variables and data types are used? Where are the strings, integers, and floats?
    • What functions from the random module are used, and why?
    • Where are the comments, and what do they tell you?
  4. Once you have a good sense of what the script does, open a terminal, navigate to the directory where you saved the script, and run it. Does it do what you expected?

Here are you scripts to read and run. Have fun with them!

For die.py, how would you change the program to simulate rolling 2 dices?

For password_generator.py, how would you generate a password that was, instead of a fixed 10 characters long, a random length between 10 and 14 characters?


Success!

You have master lists and loops, two of the most important concepts in this course. Keep practicing!