#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Perfect Number Python Program


    Your task for lab5 is to write a program that takes a positive integer from the user as input and prints whether it is a perfect number or not.
    If the user enters a negative number, 0, or a floating point number, you should not continue and inform the user the number needs to be a positive integer. (Use the type function to help) You can end your program by making a call to sys.exit(). You'll need to import sys to be able to use sys.exit()
    You should loop through all integers less than the input integer, and add them together if they are divisors of the input integer.
    To loop through all integers less than the integer <number> you use the following format:
    view sourceprint?
    for i in range(1, number):
    #do something with i
    The modulus operator in python is the percent symbol '%'.
    The modulus of two numbers A % B is the remainder after dividing A by B.

    THIS is the info given to me
    Any help would be nice
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Location
    Saint-Petersburg, Russia
    Posts
    240
    Rep Power
    29
    Any help would be nice
    Perhaps, since it is your assignment, it is worth starting to write program and when you stick somewhere - asking for specific advise?

    Or you simply prefer someone to write the whole matter instead of you? I'm sorry, but I do not think this is both decent and able to teach you anything...
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Response


    Originally Posted by rodiongork
    Perhaps, since it is your assignment, it is worth starting to write program and when you stick somewhere - asking for specific advise?

    Or you simply prefer someone to write the whole matter instead of you? I'm sorry, but I do not think this is both decent and able to teach you anything...
    Your right, that came off wrong, im working on it right now but i should probably wait till ive got something and have hit a spot where i dont know where to go from next. Sorry about the misunderstanding, didnt mean to make it seem as if i wanted someone to write it for me.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Location
    Saint-Petersburg, Russia
    Posts
    240
    Rep Power
    29
    I recommend you to start as following

    1. Write a program which inputs number and prints it back again.

    2. Modify the program so it inputs number (N) and starts a loop from 1 to this number, printing all values (i.e. 1, 2, 3... N) on separate lines.

    3. Modify the program, so it prints not every number, but only those by which N could be divided without remainder.

    4. Modify the program so that these numbers are summed up instead of printing.

    5. Modify the program to check whether this sum equals to N.

    Official Python 3 tutorial could be of great help to you. (if you use Python 2, switch to other version of tutorial)
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,966
    Rep Power
    481
    I recommend that you not include N along with the other divisors.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo