String Processing Anna Univ 1st Sem PSPP Lab
String Processing Anna Univ 1st Sem PSPP Lab
'''
str = input('Enter the string: ')
len = 0
for i in str:
len = len + 1
print('Length of the string is: ',len)
'''
#printing vertically
'''
str = input('Enter the string: ')
for i in str:
print(i)
'''
#print the alternate characters
'''
str = input('Enter the string: ')
pos = 0
for i in str:
if(pos%2 == 0):
print(i, end='')
pos = pos + 1
'''
#find the sum of ASCII values of individual characters of the string
'''
str = input('Enter the string: ')
sum = 0
for i in str:
sum = sum + ord(i)
print('The sum is: ', sum)
'''
#reversing the string
'''
str = input('Enter the string: ')
rev = ''
for i in str:
rev = i+ rev
print(rev)
'''
#finding a particular character
'''
str = input('Enter the string: ')
ch = input('Enter the character to be found in the string: ')
index = 0
found = False
for i in str:
if(i == ch):
found = True
break
index += 1
if(found):
print('{} found at location: {}'.format(ch, index))
else:
print('Not found')
'''
#deleting a particular character
'''
str = input('Enter the string: ')
ch = input('Enter the character to be deleted: ')
new = ''
for i in str:
if(i != ch):
new = new + i
print(new)
'''
#inserting a character after the location
'''
str = input('Enter the string: ')
loc = int(input('Enter the location: '))
ch = input('Enter the char to be inserted: ')
pos = 0
new = ''
for i in str:
if(pos != loc):
new = new + i
else:
new = new + i + ch
pos = pos + 1
print(new)
'''
#encrypt & decrypt
'''
def encrypt(str, key):
new = ''
for i in str:
new = new + chr(ord(i)+key)
return new
str = input('Enter the string: ')
key = int(input('Enter the key value to be used for encryption: '))
newstr = encrypt(str, key)
print('enc: ', newstr)
'''
#character count
'''
str = input('enter the string: ')
ch = input('enter a character: ')
cnt = 0
for i in str:
if(i == ch):
cnt += 1
print(cnt)
'''
#male of female
'''
str = input('Enter the name: ')
len = 0
for i in str:
pass
if(i in ['a','e','i','o','u']):
print('female')
else:
print('male')
'''
#diagonal print
'''
str = input('Enter the string: ')
cnt = 0
for i in str:
for j in range(cnt):
print(' ', end='')
print(i)
cnt += 1
'''
#scrolling a msg
'''
def print_blank(cnt):
for i in range(cnt):
print(' ', end='')
def delay():
for i in range(20000):
for j in range(2000):
pass
import os
str = input('Enter a msg: ')
for i in range(25):
print_blank(i)
print(str, end='')
#delay()
input()
os.system('cls')
'''
#permuting a string (legth of three)
'''
str = input('enter a string: ')
for i in range(3):
for j in range(3):
for k in range(3):
if(i!=j and i!=k and j!=k):
print(str[i],str[j],str[k], sep='')
'''
#occurance of a character
'''
str1 = input('Enter the string: ')
ch = input('Enter a character: ')
loc = 0
msg = ''
for i in str1:
if(i == ch):
msg = msg + str(loc) + ','
loc += 1
print(msg)
'''
#clubbing two strings of equal length
str1 = 'abc'
str2 = '123'
'''
cnt = 0
new = ''
for i in str1:
cnt += 1
for i in range(cnt):
new = new + str1[i] + str2[i]
print(new)
'''
'''
new = ''
for i,j in str1, str2:
new = new + i + j
print(new)
'''
'''
new = ''
for i in str1:
for j in str2:
new = new + str1 + str2
print(new)
'''