Reputation: 304
I'm currently writing a code that asks the user for an integer and calculates the number of divisors the integer has. I've finished the code but am stuck on the "returning part". This is what I've got so far:
def findDivisors(number):
decrease = number
count = 0
while ( decrease >= 1):
if ( number%decrease == 0 ):
count=count+1
decrease=decrease-1
def main(count):
number = int(input("Please enter a positive integer : "))
print(count)
main()
I've tried returning both "number" and "count" but can't seem to make it work. Any suggestions ? BTW, I'm using Python 3.3.1
Upvotes: 0
Views: 41
Reputation: 10841
return count
at the end of the function findDivisors()
.findDivisors()
appears to be incorrect (decrease=decrease-1
should be indented as much as the first line of the if
statement.count
as a parameter to the main()
function, especially when you are calling main()
without any parameters.findDivisors()
. I'd suggest replacing the print
call with print(findDivisors(number))
.Upvotes: 1