Jump to content

Skillshare intro to Python/Unit 4: Difference between revisions

no edit summary
imported>Jesstess
imported>Jesstess
No edit summary
 
(9 intermediate revisions by the same user not shown)
__NOTOC__
 
== Goal #1: using modules ==
 
(Estimated completion time: 15 - 30 minutes)
 
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.
<b>Here are you scripts to read and run</b>. Have fun with them!
 
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit4/die.py nobeldie.py]
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit4/password_generator.py 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?
 
 
== Goal #2: reading from files ==
 
(Estimated completion time: 15 - 30 minutes)
 
To get some more practice with reading from files, we're going to read, run, and extend some Python scripts.
 
=== Countries example ===
 
Here are the country names text file and Python script from the lesson:
 
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit5/countries.txt countries.txt]
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit5/countries.py countries.py]
 
Please download both files and save them to your Desktop. Review <code>countries.py</code>, make sure you understand it, and then run it!
 
Then, <b>add code to the file to answer the following questions</b>:
* What are all of the countries that end in "land"?
* What is the shortest country name?
 
 
=== Wordplay example ===
 
Here are two new files. The first, <code>sowpods.txt</code>, is the official Scrabble wordlists we'll use for our Scrabble cheater. The second is a Python script that uses data from <code>sowpods.txt</code> to find weird and interesting words:
 
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit5/sowpods.txt sowpods.txt]
* [http://web.mit.edu/jesstess/www/SkillsharePython/Unit5/wordplay.py wordplay.py]
 
Please download both files and save them to your Desktop. Open <code>wordplay.py</code>, see if you can guess what it does, and then run it!
 
Then, using the existing code as a template, <b>add code to the file to answer the following questions</b>:
* What are all of the words that contain "VV"?
* What are all of the words that contain "Q" without a "U"?
* What are all of the words that contain all of the vowels and Y, ("A", "E", "I", "O", "U", "Y") in any order?
 
What other weird words can you find?
 
 
==Success!==
 
You have mastermastered listsmodules and loops, two of the most important conceptsfiles in this coursePython. Keep practicing!
 
[[File:Champagne.png|100px]][[File:Party.png|125px]]
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.