Back
You can create your own function that will evaluate weather the number is a perfect number or not:
def is_square(apositiveint): x = apositiveint // 2 seen = set([x]) while x * x != apositiveint: x = (x + (apositiveint // x)) // 2 if x in seen: return False seen.add(x) return Truefor i in range(110, 130): print i, is_square(i)
def is_square(apositiveint):
x = apositiveint // 2
seen = set([x])
while x * x != apositiveint:
x = (x + (apositiveint // x)) // 2
if x in seen: return False
seen.add(x)
return True
for i in range(110, 130):
print i, is_square(i)
If you are newbie and want to explore more about Python, then learn python from the below video tutorial:
31k questions
32.8k answers
501 comments
693 users