[Tutor] Python Help
alan.gauld at btinternet.com
Tue Sep 28 12:18:28 CEST 2010
"masawudu bature" <mass02gh at yahoo.ca> wrote
> The output is suppose to count the number of even divisors the range
You need to work this through again in your head:
> def evenCount(b) :
This function takes a parameter b but you never use b in the
> for n in range(x, y+1) :
What are x and y supposed to be? They must be defined
outside the function? Don;t you really want your loop to check
the values for b? So it would be range(0,b+1)?
> count = 0
You reset count to zero for each time through the loop - do
you really want to do that?
> if n % 2 == 0 :
> count += n/3
Why do you add n/3?
> count % n == 1
This is a boolean expression that will evaluate to TRue or False
and which you then ignore. It does nothing useful.
> return n
And this will always return the first value of your loop, x.
Try working through it on paper, writing down the values of each
in the function for each time through the loop. Are they what you
Author of the Learn to Program web site
More information about the Tutor