-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4. Q4.py
More file actions
32 lines (26 loc) · 861 Bytes
/
4. Q4.py
File metadata and controls
32 lines (26 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def is_prime(n):
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def is_perfect(n):
if n < 1:
return False
return sum(i for i in range(1, n) if n % i == 0) == n
def is_armstrong(n):
digits = [int(d) for d in str(n)]
power = len(digits)
return sum(d ** power for d in digits) == n
def is_palindrome(n):
return str(n) == str(n)[::-1]
def is_automorphic(n):
squared = str(n ** 2)
return squared.endswith(str(n))
num = int(input("Enter a number: "))
print(f"{num} is Prime: {is_prime(num)}")
print(f"{num} is Perfect: {is_perfect(num)}")
print(f"{num} is Armstrong: {is_armstrong(num)}")
print(f"{num} is Palindrome: {is_palindrome(num)}")
print(f"{num} is Automorphic: {is_automorphic(num)}")