Apr-02-2019, 11:22 PM
Everyone, Lisp, Prolog, Python, and Haskell are my favorite programming languages partly because I love functional programming. But I know that Prolog is a logic programming language instead of a functional one.
Anyhow, I wonder what you'll think of this program and whether I know how to reason like a Python programmer.
A perfect number is a number that equals the sum of its divisors.
Anyhow, I wonder what you'll think of this program and whether I know how to reason like a Python programmer.
A perfect number is a number that equals the sum of its divisors.
import math def divides(dividend, divisor): return dividend % divisor == 0 def divisors_of(number): last = math.trunc(math.sqrt(number)) + 1 return [divisor for divisor in range(2, last) if divides(divisor, number)] def perfect(number): return number == sum(divisors_of(number))