πππMonday Challenge πππ. Write a program that prints out perfect numbers, within user's input and checks if user input is.
12 Answers
New AnswerA 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/27/2017 4:23:19 PM
Justine Ogaraku12 Answers
New Answer@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.
Thank you for the challenge π Here's my try : https://code.sololearn.com/c898Ttt3XFUk/?ref=app
@Yash the factors of 28 are 1,2,7,14. The number itself isn't regarded as a Factor of itself.
heres mine it prints all perfect numbers upto 100k https://code.sololearn.com/cash3C558mmk/?ref=app
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
@Justine 7 * 4 = 28 so I too don't understand what you're looking for. The '4' is not accounted for in your answer.
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message