[Tutor] help understanding part of the tutorial...

Michael Janssen Janssen@rz.uni-frankfurt.de
Thu Jan 9 09:13:04 2003


On Thu, 9 Jan 2003, Guess Who? Me wrote:

[snip - unpythonic written tutorialcode ;-)]

>         if check_question(questions[index]): <<<<problem
>             right = right + 1

[snip - upwtc]

> I don't understand how this if loop returns a value using true and false - I
> know that true=1 and false=0, but I don't get how right=right+1 works out -
> does it mean that if the statement returns a false answer, the rest of the
> if loop doesn't get carried out?
Yes, you're right (but don't call it "if loop" as Magnus has stated).

> Because it seems to me right=right+1 would
> give you a minimum of three right answers, because you asked three questions
> - I'm obviously missing some concept, could somebody fill me in?

maybe you've missed, that you can use:

if 1: # no testing, this if_condition is always true
    ...do something...

if a_variable_you_have_defined_earlier == 5: # a test
    ...do something...


if a_function_that_returns_something(): # takes the
                                        # returnvalue of this
                                        # function as if_condition
    ...do something...


In my opinion this code isn't very helpfull even for learning purpose
because its comments simply duplicate the programm logic. It's not
helpful to prevent the learner from understanding the smallest part of
code on his own and instead make him read everything as comments.

On the other hand this code obfusciate a bit in using "true" and "false"
were a simple 0 or 1 would be enough. The while loop should be a "for elem
in question" loop. The intention for both might be to write code as
similar to non-programmer thinking as possibly. But I'm wondering if the
author of the tutorial really want to provide a section about "using 1 and
0 for true and false in the (common) case it is completly sufficient" to
lead the expierenced learners to a deeper insight what kind programming
is ;-)

Do not start learning with learning bad habits.

Michael

>
> Thanks!
> Travis
>
>
>
> _________________________________________________________________
> The new MSN 8 is here: Try it free* for 2 months
> http://join.msn.com/?page=dept/dialup
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>