Untitled
unknown
plain_text
a month ago
1.1 kB
0
Indexable
Never
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return True def is_armstrong(n): """Check if a number is an Armstrong number.""" num_str = str(n) num_digits = len(num_str) sum_of_digits = sum(int(digit) ** num_digits for digit in num_str) return n == sum_of_digits def is_perfect(n): """Check if a number is a perfect number.""" sum_of_divisors = 0 for i in range(1, n): if n % i == 0: sum_of_divisors += i return n == sum_of_divisors def is_fibonacci(n): """Check if a number is a Fibonacci number.""" x, y = 0, 1 while y < n: x, y = y, x + y return y == n # Test the functions num = int(input("Enter a number: ")) print("Is Prime:", is_prime(num)) print("Is Armstrong:", is_armstrong(num)) print("Is Perfect:", is_perfect(num)) print("Is Fibonacci:", is_fibonacci(num))
Leave a Comment