[Tutor] help on newbie program

Nick Jensen njensen@utahfirst.com
Thu May 29 13:18:03 2003


>It's a long time since I was a newbie... There are
>certainly some books aiming at beginners. I'd like
>to hear comments from others.

>There is Alan Gauld's "Learn to Program using Python" which
>is aimed at complete beginners. Alan also have a web site at
>http://www.freenetpages.co.uk/hp/alan.gauld/

>So is "How to Think Like a Computer Scientist: Learning with Python"
>which is also on line at http://www.ibiblio.org/obp/thinkCSpy/
>That is a bit more academic than Alans book.

>For more about Python books, see
>http://www.thinkware.se/cgi-bin/thinki.cgi/PythonDocs
>http://www.python.org/cgi-bin/moinmoin/IntroductoryBooks
>http://gnosis.cx/publish/programming/charming_python_b8.txt
>http://gnosis.cx/publish/programming/charming_python_b3.txt
>http://gnosis.cx/publish/programming/charming_python_12.txt
>and of course
>http://www.amazon.com/exec/obidos/search-handle-form/ref=3Ds_b_rs/103-11=
50007-9287854

>Anyway, this is becoming a FAQ I think. Maybe we should have a
>FAQ page somewhere on the web?

Sounds like a good idea.
-----------------
>I'm a newbie and to learn the basis of python
>I'm reading the Introduction to Python written by
>Mark Lutz and David Asher.
>It's a clear book well written
-----------------
>Although I spent a little time learning Perl before moving over to
>Python, I still consider myself to be a newbie. So far I've used most =
of
>the books already mentioned by others.=20

>For me it has helped to read several books, even moving back and forth
>between them on particular topics. Each author approaches the
>information in a unique way and sometimes when I'm stuck on one =
author's
>explanation, reading a different author on the topic is really helpful.
>I've had most of my "light bulb" moments that way. One book that I
>haven't seen mentioned is Dive Into Python
>(http://www.diveintopython.org). It's billed as an introduction to
>Python for experienced programmers but I found it to be the best book
>I've read on Python so far.

Guys thanks so much for the feedback about the books. I think I'll read =
some reviews about those suggestions on the net and pick up a book this =
weekend. It helps to get other people's views...


Magnus,

I appreciate your explanation about functions. After going over your =
examples and then going back over the program again I think I've finally =
seen the light =3D).

I think two things were hanging me up on this program. One was how the =
functions passed info around which you helped me understand. The other =
one is that I did not understand how a list within a list works and how =
to access information inside of it. I didn't understand indexing for a =
list of lists. But I think I finally see the pattern in the program. Let =
me explain how I believe it works and see if that is correct.



We have faction get_questions.

def get_questions():
    # notice how the data is stored as a list of lists
    return [["What color is the daytime sky on a clear day?","blue"],\
            ["What is the answer to life, the universe and =
everything?","42"],\
            ["What is a three letter word for mouse trap?","cat"]]

When run_test(get_questions()) is run, the entire list of lists that is =
returned from get_questions() is passed back into run_test.

So then run_test function is run and the first if statement is false so =
it is skipped. Then the while loop is run because it is true. Then we =
have

>>>if check_question(questions[index]):

This is part of what I did not understand, but now I think I do. Index =
at this point is 0. So what we have is index 0 of the list which would =
be ["What color is the daytime sky on a clear day?","blue"].=20

Then that is put into the check_questions function as =
question_and_answer. From there the question is extracted from that =
single list and then the answer is extracted as well. That was not =
making sense to me at first. I didn't know if index 0 was the first list =
or just the first question in the get_questions function. That was =
really fowling me up. It seems that you need to extract a list from the =
list first and then extract the info inside of that list.=20

Then run_test is run two more times for the other two lists passing them =
into check_question each time.

Finally the results are computed and printed out in

>>>print "You got ",right*100/len(questions),"% right out =
of",len(questions)

I think my mind just needs conditioning to be able to think like a =
programmer. I've been working with computer networks, but never =
programming and my brain wants to resist it, but I won't let it win. =
=3D)

Thanks again for your assistance...

-Nick





=20