+ 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

27th Nov 2017, 4:23 PM
Justine Ogaraku
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.
30th Nov 2017, 1:14 AM
Justine Ogaraku
+ 10
27th Nov 2017, 4:25 PM
Justine Ogaraku
+ 10
Thank you for the challenge 😊 Here's my try : https://code.sololearn.com/c898Ttt3XFUk/?ref=app
1st Dec 2017, 8:24 PM
LukArToDo
+ 9
@Yash the factors of 28 are 1,2,7,14. The number itself isn't regarded as a Factor of itself.
29th Nov 2017, 10:40 PM
Justine Ogaraku
27th Nov 2017, 9:51 PM
Maya
+ 3
heres mine it prints all perfect numbers upto 100k https://code.sololearn.com/cash3C558mmk/?ref=app
27th Nov 2017, 5:52 PM
sayan chandra
+ 3
https://code.sololearn.com/c5F97g72W2vs/?ref=app
27th Nov 2017, 8:37 PM
...
+ 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
29th Nov 2017, 8:32 AM
Sarthak Gupta
+ 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.
30th Nov 2017, 12:06 AM
Mike Weiss
1st Dec 2017, 9:43 AM
Francisco Martínez
+ 1
https://code.sololearn.com/cE9YRe62MFVc/?ref=app
28th Nov 2017, 11:14 AM
Arun