You are on page 1of 3

UNIT – 2

Experiment – 2.1

Name: Sahil Arora UID: 21BCS7498


Branch: CSE Section: 21BCS 702-A
Semester: 4 Date of Performance: 03-04-2023
Subject: Programming in Python Subject Code: 21CSP-259

Aim: - On the basis of the string develop the code for the following.
Program 2.1.1:

Write a python program to Check whether a string is Symmetrical or Palindrome.

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:

Write a python program to find uncommon word from two strings.

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.

You might also like