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

Recent Changes File

The document contains a series of programming exercises that demonstrate various string and list manipulations in Python. Each program includes user input, processing logic, and outputs based on specific conditions, such as checking for palindromes, counting occurrences of substrings, and finding maximum values in lists. The outputs for each program are referenced on specific pages.

Uploaded by

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

Recent Changes File

The document contains a series of programming exercises that demonstrate various string and list manipulations in Python. Each program includes user input, processing logic, and outputs based on specific conditions, such as checking for palindromes, counting occurrences of substrings, and finding maximum values in lists. The outputs for each program are referenced on specific pages.

Uploaded by

priyanshu111das
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OUTPUT 13

25
PROGRAM 13

13. Program to read a string and display it in the form:


First character last character
Second character Second last character
: :
For Example, string “try” should print as:
t y
r r
y t

string=input("Enter a String :")


length=len(string)
i=0
for a in range(-1,(-length-1),-1):
print(string[i],"\t",string[a])
i+=1
Answer: For the above program the output is shown in Page no.25:

26
OUTPUT 14

27
PROGRAM 14
14. Write a Program to input two strings. If string1 is contained in string2, then create a third
string with first four character of string 2’ added with ‘restore’:

S1=input("Enter String1 :")


S2=input("Enter String2 :")
print ("Original Strings :",S1,S2)
if S1 in S2 :
S3=S2[0:4] + "Restore"
print("Final String :",S1,S3)

Answer: For the above program the output is shown in Page no.27:

28
OUTPUT 15

29
PROGRAM 15

15. Write a program to input a string and check if it is a palindrome string using a string slice:

s=input("Enter a String:")
if (s==s[::-1]):
print(s,"is a palindrome.")
else :
print(s,'is NOT a palindrome')

Answer: For the above program the output is shown in Page no.29:

30
OUTPUT 16

31
PROGRAM 16

16. Program that reads a line and a substring. It should then display the number of
occurrences of the given substring in the line:

line=input("Enter line:")
sub=input("Enter substring :")
length=len(line)
lensub=len(sub)
start=count=0
end=length
while True :
pos=[Link](sub,start,end)
if pos != -1:
count+=1
start=pos+lensub
else:
break
if start>=length:
break
print("No. of Occrrences of",sub,':',count)

Answer: For the above program the output is shown in Page no.31:

32
OUTPUT 17

33
PROGRAM 17

17. Program to search for an element in a given list of numbers:

lst=eval(input("Enter a List :"))


length=len(lst)
elem=int(input("Enter element to be searched for :"))
for i in range(0,length):
if elem ==lst[i]:
print(elem,"foundat index",i)
break
else:
print(elem,"NOT Found in given list")

Answer: For the above program the output is shown in Page no.33:

34
OUTPUT 18

35
PROGRAM 18

18. Program to count the frequency of a given element in a list of numbers:

lst=eval(input("Enter a List :"))


length=len(lst)
elem=int(input("Enter element :"))
count=0
for i in range(0,length):
if elem == lst[i]:
count+=1
if count==0:
print(elem,"Not found in given list")
else:
print(elem,'has frequency as',count,'in given list')

Answer: For the above program the output is shown in Page no.35:

36
OUTPUT 19

37
PROGRAM 19

19. Write a program to input two lists and display the maximum element from the elements of
both the lists combined, along with its index in its list:

lst1=eval(input("Enter List 1 :"))

lst2=eval(input("Enter List 2 :"))

mx1 = max(lst1)

mx2 = max(lst2)

if mx1>=mx2 :

print(mx1,"The maximum value is in list 1 at index ",[Link](mx1))

else:

print(mx2,"The maximum value is in list 2 at index :",[Link](mx2))

Answer: For the above program the output is shown in Page no.35:

38

You might also like