[Tutor] Question

Michael Hall michael.hall5447 at gmail.com
Sat Dec 3 09:31:02 CET 2011


# 1) a perfect number is a positive integer that is equal to the
# sum of its proper positive divisors,excluding the number itself.
# for example, 6 is a perfect number because it is evenly divisible
# by 1, 2 and 3 - all of it's divisors - and the sum 1 + 2 + 3 = 6.
# a) write a function, getDivisors(), that returns a list of all
# of the positive divisors of a given number. for example -
# result = getDivisors(24)
# print(result)
# would yield: "[ 1, 2, 3, 4, 6, 8, 12]"



def main():

    num = int(input('Please Enter a Number: '))
    getDivisors(num)


def getDivisors(num):
    my_list = []
    sum = 0
    for number in range(1, num, 10000):

        if num % number == 0:
            print([1, 2, 3])
            sum += num


    print('The sum is ', sum)
    if sum == num:
        print(num, 'is a perfect number')
    else:
        print(num, 'is not a perfect number')



main()

Andreas and others "Thank you for your help. I am still having an issues. I
went to the links and they were very helpful. Here is my problem. If you
enter the number 6 the program is just what the teacher wants. My problem
is if you enter any other number it is wrong. AGAIN, I AM NOT. I REPEAT I
AM NOT ASKING YOU OR ANY OF YOU TO WRITE MY PROGRAM OR DO MY HOMEWORK. I am
asking for a solution to the problem. The program has been written I
just need help. Thank you in advance. On Fri, Dec 2, 2011 at 1:55 AM,
Andreas Perstinger <andreas.perstinger at gmx.net> wrote:

> On 2011-12-02 08:22, Michael Hall wrote:
>
>> I am still not understanding what it is I am being asked to do.
>>
>
> Ok, forget about your working program and just concentrate on question
> 1a):
>
>
> > # a) write a function, getDivisors(), that returns a list of all
> > # of the positive divisors of a given number. for example -
> > # result = getDivisors(24)
> > # print(result)
> > # would yield: "[ 1, 2, 3, 4, 6, 8, 12]"
>
> I suppose you know how functions and lists works, do you?
> You have to write a function named "getDivisors" which takes one argument
> (a number) and returns a list. Nothing more, nothing less.
>
> You started right with the line
>
> def getDivisors(num):
>
> but in all your attempts you have never returned a value. Do you know how
> a function can return something?
>
> In your case you have to return a list. Therefore you have to build this
> list inside the function. You don't need to print the values or calculate a
> sum, just add every divisor to the list. I'm sure you have learned already
> how lists works, haven't you?
>
> If you have problems understanding functions and lists, you should re-read
> these parts in your learning material or in the online tutorial:
> http://docs.python.org/py3k/**tutorial/introduction.html#**lists<http://docs.python.org/py3k/tutorial/introduction.html#lists>
> http://docs.python.org/py3k/**tutorial/controlflow.html#**
> defining-functions<http://docs.python.org/py3k/tutorial/controlflow.html#defining-functions>
> http://docs.python.org/py3k/**tutorial/datastructures.html#**more-on-lists<http://docs.python.org/py3k/tutorial/datastructures.html#more-on-lists>
>
>
> I am asking if you are given the following question how would you
>> write the program.
>>
>
> Sorry, we won't write the program for you. You have to do it yourself. We
> will just try to give you some hints - if you carefully read the links I've
> mentioned you'll find an example which comes close to yours :-).
>
> Bye, Andreas
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111203/4f5ca538/attachment.html>


More information about the Tutor mailing list