Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding perfect numbers
#3
(Apr-03-2019, 01:30 AM)ichabod801 Wrote: I would have used not number % divisor, and not bothered with the divides function.

Also, your code does work right. It returns False for 6. Going to the sqrt(n) is fine for checking for primes, but if you need all of the divisors it's going to miss lots.
Ichabod, you mean that my code doesn't work, right? I'll find and correct the bug. Thanks for revealing it.

You make a good point about the divides function. Maybe I'm to OCD about boolean expressions because I'm a purist. So years ago, when my Sun workstation complained that I put a non-boolean expression in a C program's while-loop condition, I replaced it with a boolean one.

Another purist pet peeve of mine is a break statement that stops a loop before the loop condition comes true or gets falsified. That's why I'd much rather force that condition to be true or force it to be false.
Reply


Messages In This Thread
Finding perfect numbers - by BillMcEnaney - Apr-02-2019, 11:22 PM
RE: Finding perfect numbers - by ichabod801 - Apr-03-2019, 01:30 AM
RE: Finding perfect numbers - by BillMcEnaney - Apr-03-2019, 02:04 AM
RE: Finding perfect numbers - by ichabod801 - Apr-03-2019, 03:07 AM
RE: Finding perfect numbers - by BillMcEnaney - Apr-03-2019, 05:15 AM
RE: Finding perfect numbers - by micseydel - Apr-04-2019, 03:44 AM
RE: Finding perfect numbers - by BillMcEnaney - Apr-04-2019, 04:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Are there errors in the code for my coin toss systems? Matlibplot is too perfect . Coolkat 0 412 Nov-13-2023, 11:54 AM
Last Post: Coolkat
  Perfect numbers Vidar567 2 1,941 Nov-23-2020, 10:29 PM
Last Post: Vidar567
  Runs perfect in Python but fails to print last statement when converted to .exe. Help sunil422 3 2,867 Aug-13-2020, 01:22 PM
Last Post: deanhystad
  Finding line numbers starting with certain string Sutsro 3 2,593 Jun-27-2020, 12:36 PM
Last Post: Yoriz
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,787 May-09-2019, 12:19 PM
Last Post: Pleiades
  Help with try and open 6.txt file and print as perfect or not Pleiades 13 5,313 Jan-03-2019, 10:14 PM
Last Post: Pleiades
  Finding prime numbers creslin_black 7 4,436 Jul-20-2018, 02:28 PM
Last Post: grjmmr
  Perfect Number formula in Python Question an Mersenne Numbers Pleiades 5 6,133 May-16-2018, 04:56 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020