0% found this document useful (0 votes)
2 views4 pages

N 6 For I in Range (N) : T 65 For J in Range (I+1) : Print (CHR (T), End T+ 1

Uploaded by

ragunesh26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

N 6 For I in Range (N) : T 65 For J in Range (I+1) : Print (CHR (T), End T+ 1

Uploaded by

ragunesh26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical 3

Print the output of code in palindrome


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

# Test the functions


num = 153
if is_armstrong_number(num):
print(f"{num} is an Armstrong number.")
else:
print(f"{num} is not an Armstrong number.")

if is_perfect_number(num):
print(f"{num} is a perfect number.")
else:
print(f"{num} is not a perfect number.")

Practical 5

Check whether given no 10 is prime or not

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

# Test the function


num = 10
if is_prime(num):
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")

Practical 6
No of terms and Fibonacci sequence

def fibonacci(n):
fib_sequence = [0, 1]
if n <= 1:
return fib_sequence[:n+1]

for i in range(2, n+1):


next_term = fib_sequence[-1] + fib_sequence[-2]
fib_sequence.append(next_term)
return fib_sequence

num_terms = 10 # Change this number to the desired number of terms

fib_sequence = fibonacci(num_terms - 1) # Subtracting 1 to account for 0-based indexing

print("Number of terms:", num_terms)


print("Fibonacci sequence:", fib_sequence)

Practical 7

Check the lcm and gcd of 1 and 0


import math
num1 = 1
num2 = 0

# Calculate GCD
gcd = math.gcd(num1, num2)

# Calculate LCM
lcm = 0

print("GCD of", num1, "and", num2, "is:", gcd)


print("LCM of", num1, "and", num2, "is:", lcm)

Practical 8

Count the vowels and consonants of your name

name = " "


name = name.lower()

vowels = 0
consonants = 0

for char in name:


if char in "aeiou":
vowels += 1
elif char.isalpha():
consonants += 1

print("Name:", name)
print("Vowels:", vowels)
print("Consonants:", consonants)

Practical 9

Check whether the string is palindrome or not

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]

# Test the function


input_string = "A man a plan a canal Panama"
if is_palindrome(input_string):
print(f"'{input_string}' is a palindrome.")
else:
print(f"'{input_string}' is not a palindrome.")

Practical 10

Generate numbers based on list size

num_list = []
n = int(input("Enter list size: "))
for _ in range(n):
number = int(input("Enter a number: "))
num_list.append(number)

print("Your number list:", num_list)


print("Minimum number:", min(num_list))

Practical 11

Pattern using nested loops

rows = 5

for i in range(rows):
for j in range(i + 1):
print("*", end="")
print()

Practical 12

Number patterns using nested loops

rows = 5

for i in range(rows, 0, -1):


for j in range(1, i + 1):
print(j, end="")
print()

You might also like