0

Check whether a number is perfect or not and return y or n accordingly

Use function

9th Nov 2020, 9:43 AM
Manpreet Singh
3 odpowiedzi
+ 1
Please define a Perfect Number. Saves me having to Google search
9th Nov 2020, 10:35 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
def pn_check(n): if n== 1: print(str(n) + " is NOT a prime number.") a = 0 for i in range(1,n+1): # avoid ZeroDivisionError if n % i == 0: a += 1 if a > 2: print(str(n)+ " is NOT a prime number.") break if a == 2: print(str(n)+ " is a prime number!") m = int(input()) pn_check(m)
9th Nov 2020, 9:45 AM
Manpreet Singh
0
My attempt
9th Nov 2020, 9:45 AM
Manpreet Singh