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 8733981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:45:17+00:00 2026-06-13T09:45:17+00:00

The code: total = 0 for number in xrange(10000): divisors = 0 divisors2 =

  • 0

The code:

total = 0

for number in xrange(10000):
    divisors = 0
    divisors2 = 0

    for dividend in xrange(1, number/2):
        if number % dividend == 0:
            divisors = divisors + dividend

    for dividend2 in xrange(1, divisors/2):
        if divisors % dividend2 == 0:
            divisors2 = divisors2 + dividend2

    if number == divisors2:
        total = total + number + divisors

print total 

The code is supposed to generate amicable numbers(i.e. number that total number of divisors less than itself equal another number that’s total number of divisors equal the original number, see Project Euler, problem 21) under 10,000 and add them as it finds them. It’s generating 48, which is way too low.

The program ran a lot faster than I expected it to: I’m running through a lot of numbers and I know for a fact that this isn’t a very fast way to get the proper divisors, so I suspected something was up with the loop, either that Python was just stopping unexpectedly, or was running the loops out of order. If I put a command to print divisors before the beginning of the next loop, it goes on forever, and tends to print long lines of the same number. Something strange is definitely going on here. I googled “strange loop behavior”, and searched here, to no avail. I also checked [here].2

What’s going on and what should I do about it?

Thank you in advance.

  • 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-13T09:45:18+00:00Added an answer on June 13, 2026 at 9:45 am
    xrange(1, n)
    

    gives you numbers from 1 ... n-1. To get numbers from 1 ... n, you will need to do xrange(1, n+1). You make this mistake twice in your code.

    You are also not checking for the condition about a != b in the original problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that calculates a total number using Javascript. The code for
So this code will count the total number of pairs of numbers whose difference
Consider the following code. It's an anchor tag with an id called leader-module-total that
I need to get the total number of cells that are present in a
I need to know the total number of threads that my application has spawned
I want to print the total number of gamertags in a table which equals
Below is the current code I use to get the total number of photos
I'm learning Python and writing a program that keeps track of the total number
I have the below code which returns the total number of pages in my
how do you code in c sharp to fetch WMI information like total memory,cpu

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.