[Tutor] Need help adding a funcation
Michael Hall
michael.hall5447 at gmail.com
Thu Dec 1 16:33:18 CET 2011
Here is the code I have written.
# Create main function.
def main():
a = input('Please Enter a Number: ') # Ask user for input.
number = int(a)
x = 1
sum_of = 0
while number > x:
if number % x == 0:
sum_of = sum_of + x
x += 1
if sum_of == number:
print(number,'is a Perfect Number')
elif sum_of < number:
print(number,'is a Non-perfect Number')
main()
Here is the problem I am having. The program works perfect but I need to
add the following:
# 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]"
# b) write a program that uses your function to determine which
# numbers between 1 and 10,000 are perfect. (answer: 6, 28, 496
# and 8128 are perfect!)
I know that mystring needs to be added. I need help
Thank you in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111201/1df7d95b/attachment.html>
More information about the Tutor
mailing list