OUTPUT:
Exp No: 04 Name of the Student: DEEKSHITH J
Date:21/7/26 Register No:
2503717610621013 HANDLING STRINGS
AIM:
To develop the following simple Python programs using statements, data types,
Input/output and expressions.
Handling strings
SOFTWARE TOOL:
Python 3.12.4
ALGORITHM:
Step 1: Start the program
Step 2: Get the string and substring from the user.
Step 3: calculate the length of string and declare pos=-1.
Step 4: Using while loop and find the substring and its position.
Step 5: If pos=-1, then it comes out of the loop, if not find the position of
the substring Step 6: Print the no. of occurances and position of the
substring.
Step 7:Stop the program.
PROGRAM:
#find the substring
s=input("Enter the
string =")
subs=input("Enter the
substring =") flag=False
pos=-
n=len(
s) c=0
while True:
pos=[Link](subs,pos+1
,n ) if pos==-1:
FLOWCHART:
OUTPUT:
brea
c=c+
print("found at position",pos)
flag=True
if flag==False:
print("not found")
print("the number of occurances=",c)
PROGRAM:
Python program to create a Caesar encryption.
#caesar encryption
s=input("Enter the
string =") result=""
for i in range(0,len(s)):
result+= chr((ord(s[i]) - ord('a') + 3) % 26 +
ord('a')) print(result)
OUTPUT:
ALGORITHM:
Step 1: Start the program.
Step 2: Get the string and number of rotation from user.
Step 3: Do the operations
left=s[k:]+s[:k]
right=s[(n-k):]+s[:(n-
k)]
Step 4: Print the
results. Step 5: Stop
the program.
PROGRAM:
program to rotate string left and right for the
specific length. #right and left rotation
s=input("Enter the string=")
k=int(input("the number of rotation
=")) left=""
left=s[k:]+s[:k]
print(left)
right=""
n=len(s)
right=s[(n-k):]+s[:(n-k)]
print(right)
FLOWCHART:
OUTPUT:
PROGRAM:
#find acronym
s=input("Enter the
string=") result=s[0]
for i in range(1,len(s)):
if(s[i]==" "):
result+=s[i
+1]
print(result)
print([Link]())
RESULT:
The given programs are executed and verified in Python.