[Tutor] Help understanding code

Zach Smith (Linux) zach at zcsmith.com
Mon Oct 20 11:07:34 EDT 2003


Lisa Sullivan wrote:

> I am new to programming and I'm trying to teach myself Python via 
> online tutorials.  I am
>
> struggling with functions.  I wonder if someone could help me.
> Here is the URL for the program I am trying to understand:
> http://www.honors.montana.edu/~jjc/easytut/easytut/node10.html#SECTION001030000000000000000 
>
> I have worked through the program and I understand all but one line.  
> Below is an edited version
>
> of my notes while I was working through understanding the program.
> Let me know if I should post the program as well.
>
>  if get_questions(questions[index]):
> I don't understand this line.
> It seems to move through the list stored in (questions) and determine 
> whether or not to increase
>
If I'm understanding you right, you don't know why this performs what it 
does.  Any "if" statement reverts to true (asks if it is true).  In 
other words, it automatically implies true unless specifically stated 
otherwise.  Think of the line looking like this:

if get_questions(questions[index])=true then:
    run these statements/instructions

Like I said, there is an automatic implementation of true unless written 
otherwise, such as:

if get_questions(questions[index])=false then:
    run these statements/instructions

Hope this helps.

Zach




More information about the Tutor mailing list