0

Find perfect number smaller than n

Hi everyone, I tried to write a program, that returns the perfect numbers smaller than n. For example, if n is 10, the program should return "6". This is my code: https://code.sololearn.com/ca2A1A0A21a1 My problem with my code is that it returns only 1 number lower than n e.g. 9 if n=10 and so on. If I "return sum" - I get 240 if n = 10. I don't get it... Apprreciate any help!

24th Jan 2021, 2:01 PM
Binh Tan Nguyen
Binh Tan Nguyen - avatar
3 ответов
0
looks really good, but is it possible to write a code without an Array?
24th Jan 2021, 2:55 PM
Binh Tan Nguyen
Binh Tan Nguyen - avatar
0
Alright, thanks a lot Abol! Appreciate your time to help me :)
24th Jan 2021, 3:09 PM
Binh Tan Nguyen
Binh Tan Nguyen - avatar
0
Abol, I have another question 🙄 Can you show me how to print any perfect number, instead of add (i) to a list? just tried to do it, and it doesn't seem to work. It just prints out the number from 1 - (n-1).... I just updated my code, so you can see what I've changed: https://code.sololearn.com/ca2A1A0A21a1
24th Jan 2021, 3:45 PM
Binh Tan Nguyen
Binh Tan Nguyen - avatar