[Courses] [python] Lesson 3: Fun with Strings and Lists - Homework

Maria Inmaculada de la Torre idelatorreie at gmail.com
Thu Jul 7 19:47:38 UTC 2011


Really newbie and struggling so please forgive me for being late. :(

1. I couldn't get this after reading the lesson, so I did the next best
thing and use Google.
You would use the function

 size = len(a)

2. I think you can't use the negative value in a list either you have
nothing in the list or you have something, but you can't have something with
a negative order value in a list.

After Google search: It seems it's possible and what it's doing is counting
backwards, instead of counting from left to right, it's counting from right
to left

3. No idea, so Google search.

>From Wikipedia (http://en.wikipedia.org/wiki/Guido_van_Rossum)
"*Guido van Rossum* (born 31
January[2]<http://en.wikipedia.org/wiki/Guido_van_Rossum#cite_note-1>
 1956[*citation needed<http://en.wikipedia.org/wiki/Wikipedia:Citation_needed>
*]) is a Dutch <http://en.wikipedia.org/wiki/Netherlands> computer
programmer <http://en.wikipedia.org/wiki/Computer_programmer> who is best
known as the author of the Python programming
language<http://en.wikipedia.org/wiki/Python_(programming_language)>.
In the Python community, Van Rossum is known as a "Benevolent Dictator For
Life <http://en.wikipedia.org/wiki/Benevolent_Dictator_For_Life>" (BDFL),
meaning that he continues to oversee the Python development process, making
decisions where necessary."

4.

numbers = ["one", "two", "three", "four", "five"]
for n in numbers :
print n

5. Needed Google help in this one too

vals = [ 0, 2, 4, 8, 16, 18, 17, 14, 9, 7, 4, 2, 1 ]

for n in vals :

print '*' * n

This is what I get:
**
****
********
****************
******************
*****************
**************
*********
*******
****
**
*




---------- Forwarded message ----------
> From: Akkana Peck <akkana at shallowsky.com>
> To: courses at linuxchix.org
> Date: Fri, 1 Jul 2011 21:57:17 -0700
> Subject: [Courses] [python] Lesson 3: Fun with Strings and Lists
> [Trying re-sending this -- sorry if you get two copies, but the
> first one doesn't seem to have shown up.]
>
>
> ================== Homework ======================
>
> 1. How would you count the number of words in a single string?
>   Assume words are separated by spaces ... don't worry about
>   things like newlines, commas or hyphens.
>
> 2. What does an index of [-1], or another negative number mean in a
>   list or string? Take a guess, then try it and see if you were right.
>
> 3. Who is Guido van Rossum and why am I using him as an example?
>
> 4. Rewrite the exercise from lesson 2, the one where
>   you printed "one", "two", "three", "four", "five",
>   using a list instead of a series of if-elif.
>   (A few people already posted solutions that worked that way
>   in their lesson 2 answers. If you already did this for lesson 2, no
>   need to do it again. If you read other people's, it's still worth
>   writing it yourself now without going back and looking.)
>
> 5. This one's a little harder, but give it a try if you have time.
>   Plot a histogram graph from a list of numbers, with each number in
>   the list on its own line.
>
>   For instance, if you start with numbers like this:
> vals = [ 0, 2, 4, 8, 16, 18, 17, 14, 9, 7, 4, 2, 1 ]
>   you might plot something like this:
>
> **
> ****
> ********
> ****************
> ******************
> *****************
> **************
> *********
> *******
> ****
> **
> *
>    where the first line has no stars, the second has two, then 4, etc.
>    Hint: you'll need two loops, one inside the other.
>
>
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
>
>


More information about the Courses mailing list