0

this is the code for perfect number. It is a readable code?

num=int(input("enter a number here")) sum=0 for i in range(1,num+1): if num%i==0: sum+=i print(sum) if sum//2==num: print("day la perfect number",num) else: print("day ko phai perfect number")

27th Dec 2018, 12:33 AM
Khai123
Khai123 - avatar
1 Réponse
0
Readable as in do I understand what it does and how it does it? Yeah, sure, but, then again, the problem it solves is very simple and the code is very short. It's good though that your variables aren't named just x or y, which is a common mistake early on. If you want to be sure you will remember what you thought of when you wrote a piece of code, consider writing comments explaining what the code does. :)
27th Dec 2018, 7:29 AM
selwyn406
selwyn406 - avatar