Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 5 - Loops - Programming Exercises - Page 165: 5.35

Answer

code

Work Step by Step

# 5.35 (Perfect number) A positive integer is called a perfect number if it is equal to the # sum of all of its positive divisors, excluding itself. For example, 6 is the first perfect # number, because 6 = 3 + 2 + 1. The next is 28 = 14 + 7 + 4 + 2 + 1. # There are four perfect numbers less than 10,000. Write a program to find these # four numbers. for i in range(3, 10000 + 1): sum = 0 for j in range(1, (i // 2) + 1): if i % j == 0: sum += j if sum == i: print(i)
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.