kiasy
kiasy

Reputation: 304

Functions returning issue

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

Answers (1)

Simon
Simon

Reputation: 10841

  1. You need return count at the end of the function findDivisors().
  2. The indentation in findDivisors() appears to be incorrect (decrease=decrease-1 should be indented as much as the first line of the if statement.
  3. I don't see any reason why you would want count as a parameter to the main() function, especially when you are calling main() without any parameters.
  4. There is no evidence from the code that you've shown that you are actually calling the function findDivisors(). I'd suggest replacing the print call with print(findDivisors(number)).

Upvotes: 1

Related Questions