Downloadfile
Downloadfile
CODE:
# Function to check if a number is a perfect number
def is_perfect_number(n):
divisors_sum = sum(i for i in range(1, n) if n % i == 0)
return divisors_sum == n
if is_armstrong_number(n):
print(f"{n} is an Armstrong number.")
else:
print(f"{n} is not an Armstrong number.")
if is_palindrome(n):
print(f"{n} is a Palindrome.")
else:
print(f"{n} is not a Palindrome.")
CODE:
# Function to check if a number is prime or composite
def check_number_type(n):
if n <= 1:
print(f"{n} is neither prime nor composite.")
elif n == 2:
print(f"{n} is a Prime number.")
else:
for i in range(2, n):
if n % i == 0:
print(f"{n} is a Composite number.")
return
print(f"{n} is a Prime number.")
CODE:
# Function to display Fibonacci series
def fibonacci_series(n):
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
9. Compute the greatest common divisor and least common multiple of two
integers.
CODE:
# Function to compute GCD
def gcd(a, b):
while b:
a, b = b, a % b
return a
___________________________________________________________________
CODE:
# Function to count vowels, consonants, uppercase and lowercase characters
def count_characters(s):
vowels = "aeiouAEIOU"
vowels_count = consonants_count = uppercase_count = lowercase_count = 0
for char in s:
if char.isalpha(): # Check if the character is a letter
if char in vowels:
vowels_count += 1
else:
consonants_count += 1
if char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
print(f"Vowels: {vowels_count}")
print(f"Consonants: {consonants_count}")
print(f"Uppercase characters: {uppercase_count}")
print(f"Lowercase characters: {lowercase_count}")