Professional Documents
Culture Documents
Experiment – 2.1
Aim: - On the basis of the string develop the code for the following.
Program 2.1.1:
Program Code:
s=eval(input("Enter a string to check "));
>>> l=len(s)
>>> if(s[0:int(l/2)]==s[int(l/2):l]):
... print("The string is symmetrical");
... elif(s[0:int(l/2)]==s[-1:int((-l/2)-1):-1]):
... print("The string is palindrome");
Output:
Program 2.1.2:
Program Code:
s1=eval(input("Enter the first string"))
>>> s2=eval(input("Enter the second string"))
>>> l1=s1.split()
>>> l2=s2.split()
>>> for i in l1:
... flag=True
... for j in l2:
... if(i==j):
... flag=False
... if(flag==True):
... print(i)
...
>>> for i in l2:
... flag=True
... for j in l1:
... if(i==j):
... flag=False
... if(flag==True):
... print(i)
Output:
Program 2.1.3:
Write a python program to add ‘ing’ at the end of a given string (length should be at least 3). If the given
string already ends with ‘ing’ then add ‘ly’ instead. If the string length of the given string is less than 3,
leave it unchanged.
Program Code:
s=eval(input("Enter a string for conversion "))
>>> l=len(s)
>>> s1=""
>>> if(l<3):
... s1=s
... elif(s.endswith("ing")):
... s1=s+"ly"
... else:
... s1=s+"ing"
...
>>> print(s1)
Output:
Learning Outcomes:
1. Learnt about string and its different functions.