[Courses] [python] Lesson 3: Fun with Strings and Lists
tubuntu at testimonium.be
tubuntu at testimonium.be
Sun Jul 3 21:58:37 UTC 2011
Hi the course list,
I just join in and took previous lessons from the archives.
So, here are my feedbacks/questions for previous lessons and, of course, the results of my homeworks for the latest lesson.
> ================== Homework 1
> version of Python?
My version of python is 2.6.6 on Ubuntu 10.10
> why the language was named Python?
Haha, great! I hope we'll get some spam in our code, then!
http://www.youtube.com/watch?v=anwy2MPT5RE
:o)
Reading the answers from the archives I saw there was a Moodle system online (http://courses.linuxchix.org). How can I login there?
> ================== Homework 2
> Your first programming assignment: "99 bottles of beer" song.
I did need to read answer of Sondra to see a way to do it (without having to write little bit more then 198 lines... :o)
for i in range(99,0,-1):
if i == 1:
print 1,"Bottle of beer on the wall,",1,"bottle of beer"
else:
print i,"Bottles of beer on the wall,",i,"bottles of beer"
> How was the length of this lesson?
The lesson was kind of just fine ("yee, cool, I get it!"), but for the homework I had to cheat and read the other answers making that, as Leslie, I have spent most of the time looking over what other people did and tryed out some of their solutions. So, I would say the lesson and homework are not too short for me.
Note: I'm probably not programming-minded, because it's not the first time I try to learn some programming languages, and most of the time I never reach further then "Hello World" and the way to put lines in comments. But at least I can say "Hello World" in many languages...
And, ye, I still enjoy trying! :o)
So, thank you for making this... and for your patience! :o)
> ================== Homework 3
> 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.
>>> Nom = "Camille-Dominique de la Tour-en-Biais VX"
>>> len(Nom)
Hm, just returns the number of caracters...
>>> Nom = "Camille-Dominique de la Tour-en-Biais VX"
>>> Nom.split()
>>> len(Nom .split)
nop...
>>> Nom = "Camille-Dominique de la Tour-en-Biais VX"
>>> len(Nom .split)
nop...
>>> Nom = "Camille-Dominique de la Tour-en-Biais VX"
>>> Nom.split()
>>> print len(Nom.split)
nop...
>>> Nom = "Camille-Dominique de la Tour-en-Biais VX"
>>> Nom.split()
>>> count len(Nom.split)
nop...
>>> Nom = "Camille-Dominique de la Tour-en-Biais VX"
>>> Nom.split()
>>> count(Nom.split)
... arch!... :o/
... ok, back to cheating on other answers...
> 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.
It ask python to list ("count") beginning at end of the string.
I've try to visualize a result by typing:
>>> Name = "Camille-Dominique XVI de la Tour-en-Biais"
>>> Name[-23]
'X'
> 3. Who is Guido van Rossum and why am I using him as an example?
He's the guy who is fan of the Monthy Python that clearly say "my last name is two words, and I'd like keep it that way"...
> 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.
As usual, couldn't found it out by myself and read and test the answer of Allison and had a question: is there a "panic command" to stop "properly" a script that loops infinitively?... :o)
> 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.
:o|
... Are there any learning sessions on "How to keep a kitchen clean?" or "How to be friend with all facebook in a week?" or "How to coordinate being laying on a beach, holding a multicolor cocktail in one hand and a Valentine's day story book on the other, smiling at passing beautifull silhouettes and talking about latest shopping opportunities?"... I'm sure I've more chance to succeed in it!
:o|
Always Looking on the Bright Side of Life,
Tubuntu
More information about the Courses
mailing list