N 6 For I in Range (N) : T 65 For J in Range (I+1) : Print (CHR (T), End T+ 1
N 6 For I in Range (N) : T 65 For J in Range (I+1) : Print (CHR (T), End T+ 1
Practical 4
Check whether the given number is Armstrong or perfect number
def is_armstrong_number(num):
# Convert the number to a string to get its digits
num_str = str(num)
# Calculate the sum of the cubes of its digits
armstrong_sum = sum(int(digit)**len(num_str) for digit in num_str)
# Check if the sum equals the original number
return armstrong_sum == num
def is_perfect_number(num):
# Find the divisors of the number (excluding itself)
divisors = [i for i in range(1, num) if num % i == 0]
# Sum the divisors
divisors_sum = sum(divisors)
# Check if the sum equals the original number
return divisors_sum == num
if is_perfect_number(num):
print(f"{num} is a perfect number.")
else:
print(f"{num} is not a perfect number.")
Practical 5
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i=5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
Practical 6
No of terms and Fibonacci sequence
def fibonacci(n):
fib_sequence = [0, 1]
if n <= 1:
return fib_sequence[:n+1]
Practical 7
# Calculate GCD
gcd = math.gcd(num1, num2)
# Calculate LCM
lcm = 0
Practical 8
vowels = 0
consonants = 0
print("Name:", name)
print("Vowels:", vowels)
print("Consonants:", consonants)
Practical 9
def is_palindrome(s):
# Remove spaces and convert to lowercase for case-insensitive comparison
s = s.replace(" ", "").lower()
# Compare the original string with its reverse
return s == s[::-1]
Practical 10
num_list = []
n = int(input("Enter list size: "))
for _ in range(n):
number = int(input("Enter a number: "))
num_list.append(number)
Practical 11
rows = 5
for i in range(rows):
for j in range(i + 1):
print("*", end="")
print()
Practical 12
rows = 5