September 29th, 2013, 10:31 PM
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:
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
September 29th, 2013, 10:49 PM
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...
September 29th, 2013, 10:54 PM
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.
Originally Posted by rodiongork
September 29th, 2013, 11:03 PM
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)
September 30th, 2013, 12:29 AM
I recommend that you not include N along with the other divisors.
[/code] are essential for python code and Makefiles!