Practice problem (09/08/2023)

1.) WAP to remove the letter(character) from a string and take input from user

i/p = Edyoda
o/p = Eyoda

2.) Program to check if substring is present or not in a string

i/p = "Im learning python in edyoda "
substring = python
o/p = True

3.) Program to print duplicate from a list

i/p = [10,20,30.40,10,20]
o/p = [10,20]

4.) WAP for sum of number digits in a list

i/p = [12,45,94,34]
1+2 = 3, 4+5 =9 , 9+4 = 13 , 3+4 = 7
o/p = [3,9,13,7]

1 Like

remove the letter(character) from a string and take input from user

string = input('Enter a String: ')
letter = input(‘Enter a Letter: ‘)
result = string.replace(letter,’’, 1)
print(result)

Program to check if substring is present or not in a string

text = input('Enter a String: ')
substring = input('Enter a String which need to searched: ')
if substring in text:
print(‘true’)
else:
print(‘false’)

Program to print duplicate from a list

my_list = [10,20,30,40,20,30,50]
print('original list: ', my_list)
n=len(my_list)
duplicates=[]
for i in range(n):
k = i + 1
for j in range(k,n):
if my_list[i] == my_list[j] and my_list[i] not in duplicates:
duplicates.append(my_list[i])
print('duplicates in original list: ', duplicates)

program for sum of number digits in a list

my_list = [10,15,20,25]
print('original list: ', my_list)
my_result = []
for ele in my_list:
sum = 0
for digit in str(ele):
sum += int(digit)
my_result.append(sum)
print('sum of number digits in list: ', my_result)

1 Like

correct @prasadbhss , keep it up