Q - 1) WAP To Check Whether Ad Number Is Armstrong or Not: Code
Q - 1) WAP To Check Whether Ad Number Is Armstrong or Not: Code
CODE :
n = int(input("Enter the number: "))
a=0
org = n
while n!= 0:
r = n%10
a = a + r**3
n//= 10
if org == a:
print("yes its an Armstrong")
else :
print("not an Armstrong")
CODE:
n=5
for i in range(1,n+1):
for j in range(n-i):
print(" ",end=" ")
for j in range(i,1,-1):
print(j,end=" ")
for j in range(1,i+1):
print(j, end=" ")
print()
CODE:
n=5
for i in range(n,0,-1):
for j in range(n-i):
print(" ",end=" ")
for j in range(i,1,-1):
print(j,end=" ")
for j in range(1,i+1):
print(j, end=" ")
print()
CODE:
CODE:
s = "Hello World"
print(s)
print("Lower = ",s.lower())
print("Upper = ",s.upper())
Q-9) replace all vowels by *:
CODE:
s=input("Enter a String")
c=''
for i in s:
if i in 'AEIOUaieou':
c+='*'
else:
c+=i
print("New String =",c)
Q-12) WAP to read all words in string that start from a specific letter:
CODE:
input_string = "Apple banana apricot berry avocado"
specific_letter = "a"
specific_letter = specific_letter.lower()
words = input_string.split()
matching_words = []
for word in words:
if word.lower().startswith(specific_letter):
matching_words.append(word)
print("Original String:", input_string)
print(f"Words starting with '{specific_letter}':", matching_words)
CODE:
l = eval(input("Enter list"))
s=0
c=0
for i in l:
if i%2==0:
s+= i
else:
c+= i
print("Sum of even = ",s)
print("Sum of odd = ",c)
CODE:
input_list = ["apple", "banana", "cherry", "blueberry"]
longest_word = max(input_list, key=len)
print("Longest word:", longest_word)
Q-18) Finding the pairs for a target sum:
CODE:
input_list = [1, 3, 2, 4, 5, 3]
target_sum = int(input("Enter the sum you have target: "))
pairs = []
seen = set()
for num in input_list:
complement = target_sum - num
if complement in seen:
pairs.append((complement, num))
seen.add(num)
print(f"Pairs that add up to {target_sum}:", pairs)
CODE:
x=input("Enter a list or tuple or a set")
if type(x) is tuple:
print("It is a tuple")
elif type(x) is list:
print("It is a list")
else:
print("It is a set")
CODE:
values = input("Input some comma seprated numbers : ")
list = values.split(",")
tuple = tuple(list)
print('List : ',list)
print('Tuple : ',tuple)
CODE:
test_tup = (7, 5, 9, 1, 10, 3)
print("The original tuple is : " + str(test_tup))
res = sum(list(test_tup))
print("The sum of all tuple elements are : " + str(res))
Q22) Write a python program to Check if the given element is present in tuple or
not:
CODE:
test_tup = (10, 4, 5, 6, 8)
N = int(input("value to be checked:"))
res = False
for ele in test_tup :
if N == ele :
res = True
break
print("Does contain required value ? : " + str(res))
Q23) Write a Python program to get the 4th element from the last element of a
tuple.
CODE:
tuplex = ("p","y","t","h","o","n","p","r","o",7)
print(tuplex)
item= tuplex[-4]
print(item)