Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #7.2.1
- def factors(num):
- listfactors=[]
- for i in range(1, num+1):
- if num%i==0:
- listfactors.append(i)
- return listfactors
- #7.2.2
- def prime(n):
- if len(factors(n))==2:
- return True
- else:
- return False
- #7.2.3
- def perfect_number(n):
- sum=0
- for i in factors(n):
- sum+=i
- sum=sum-n
- if sum==n:
- return True
- else:
- return False
- print(perfect_number(6))
Add Comment
Please, Sign In to add comment