Perfect number - python

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2008
Posts: 35
Reputation: Darkangelchick is an unknown quantity at this point 
Solved Threads: 1
Darkangelchick Darkangelchick is offline Offline
Light Poster

Perfect number - python

 
0
  #1
Nov 26th, 2008
Hi guys, I'm currently working on a program to return whether an inputted number is perfect or not. I've found that the formula for the perfect number is If 2n-1 is prime then 2(n-1)(2n-1) is perfect.
I've worked out some code, but I'm stuck.

  1. Def listfactors(n):
  2. For 1=2 to n/2 sum(list)
  3. If 2 = int(2/20):
  4. List.append(i)

I need help working out with line 1, how it says
1=2 ton/2
, how do you write it so it goes up to n so I can divide it by 2?
HELP PLEASE!
Thanks
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 946
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 146
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Perfect number - python

 
0
  #2
Nov 27th, 2008
you use a range.
  1. for variable in range(n/2):
  2. #do stuff
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC