[Tutor] Python Help
David Hutto
smokefloat at gmail.com
Tue Sep 28 06:36:05 CEST 2010
On Tue, Sep 28, 2010 at 12:15 AM, masawudu bature <mass02gh at yahoo.ca> wrote:
> I'm having a hard time finding the count of divisors that are even. Help
> anybody?
>
> Here's my code.
>
> The output is suppose to count the number of even divisors the range has.
>
> def evenCount(b) :
> for n in range(x, y+1) :
> count = 0
> if n % 2 == 0 :
> count += n/3
> count % n == 1
> return n
>
>
> ### main ####
>
> x = input("Enter a starting value: ")
> y = input("Enter a stopping value: ")
>
> count = evenCount(x)
>
> for n in range(x, y+1) :
> count = 0
> if n % 2 == 0 :
> count += n/3
> print "%2d: " %n, "has%2d" %count, "even divisors",
> else :
> print "%2d: " %n, "has 0 even divisors",
> print
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
#You start with your range variables
x = input("Enter a starting value: ")
y = input("Enter a stopping value: ")
#You set a for loop for range
for num in range(x, y):
#If that number divided by 2 has a remainder of 0, it's of course even.
if num % 2 == 0:
#print the number
print num
And various other ways as well.
David
More information about the Tutor
mailing list