Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:10:41+00:00 2026-06-11T16:10:41+00:00

I did lab on perfect numbers in python it runs fine and prints numbers

  • 0

I did lab on perfect numbers in python it runs fine and prints numbers that I need. But not sure if I need to put (1, 1000) in range or (2, n+1) is fine? My instruction asking me to

“Write a python program to find all the perfect numbers from 1 to 10,000. When a perfect number is found, your logic should print it.”

What is a perfect number:

In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum). Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself) i.e. σ1(n) = 2n.

When I run my program it prints out 6, 28, 496, and 8128.

 n = 1
 while True:
     factors = [1]
     [factors.append(i) for i in range(2,n+1) if n%i == 0]
     if sum(factors) == 2*n: print n
     n += 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:10:42+00:00Added an answer on June 11, 2026 at 4:10 pm

    No need to go all the way up to n in your inner loop. You can just use range(2, n/2 + 1), and then if sum(factors) == n - 1. Your outer loop should be through range(2, 10001) (i.e. you should test every n in this range). Note that 1 is not considered a perfect number, so we shouldn’t include it in our range.

    for n in range(2, 10001):
        if sum(i for i in range(2, n/2 + 1) if n % i == 0) == n - 1:
            print n
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did you ever have the following situation: you need to store information, but a
I need help with my chiper lab. My instructions are: Write a program that
Did a simple application for line drawing with UIBezierPath, but now need a way
Did about 30 minutes worth of searching, found lots of relevant info, but none
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
Did not have luck with these examples: Javascript File remove Javascript FSO DeleteFile Method
Did actually someone make already a tutorial that shows how to customize an UITableView?
I've seen some links to lab.msdn.microsoft.com , but now all it does is give
I apologize if this question was asked already before but I could not find
Did a lot of research on this. Saw several opinions, few say I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.