+ 17

# 😁😁😁Monday Challenge 😁😁😁. Write a program that prints out perfect numbers, within user's input and checks if user input is.

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. EXAMPLE : 6 is a perfect number, because it's factors (1,2,3) add up to 6; 1+2+3=6 also: 28=1+2+7+14 So, the program will behave like this For example : user_input = 20 Output : 20 is not a perfect number. Perfect numbers within the range of 20 are........... All languages are welcome. But as always, hope Python will dominate 😋😉. Don't forget to upvote the question, so others can see it and try it out

11 Respuestas

+ 11

@Mike thanks for the observation, I mistaking omitted 4:
It's 28;1+2=3+4=7+7=14+14=28😉 Sorry for any inconveniences, lol.
Now let's code it.

+ 10

Check out, for clarification :
https://code.sololearn.com/cImpJuu8q858/?ref=app

+ 10

Thank you for the challenge 😊
Here's my try :
https://code.sololearn.com/c898Ttt3XFUk/?ref=app

+ 9

@Yash the factors of 28 are 1,2,7,14. The number itself isn't regarded as a Factor of itself.

+ 4

Here's my c++ program: https://code.sololearn.com/cOzaYUk2T4pi/#cpp

+ 3

heres mine
it prints all perfect numbers upto 100k
https://code.sololearn.com/cash3C558mmk/?ref=app

+ 3

https://code.sololearn.com/c5F97g72W2vs/?ref=app

+ 3

def perfect_number(num):
num_2=int((num/2)+1)
summation=0
for i in range(1,num_2):
if (num%i)==0:
summation=(summation+i)
i=i+1
return summation
number=int(input("Enter your number"))
a=perfect_number(number)
if a==number:
print (number,"is a perfect number")
else:
print (number,"isn't a perfecct number")
print ("Perfect numbers within the range of",number,"are:")
for k in range (1,number):
b=perfect_number(k)
if b==k:
print (k)
k+=1

+ 2

@Justine 7 * 4 = 28 so I too don't understand what you're looking for. The '4' is not accounted for in your answer.

+ 1

https://code.sololearn.com/cE9YRe62MFVc/?ref=app