0% found this document useful (0 votes)
3 views2 pages

Ans String

The document contains multiple Python code snippets demonstrating various string manipulation techniques, including replacing vowels, capitalizing consonants, swapping characters, counting palindromic substrings, checking for pangrams, and mirroring letters. Each code snippet is accompanied by example inputs and outputs to illustrate their functionality. The examples cover a range of operations such as string transformation and analysis.

Uploaded by

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

Ans String

The document contains multiple Python code snippets demonstrating various string manipulation techniques, including replacing vowels, capitalizing consonants, swapping characters, counting palindromic substrings, checking for pangrams, and mirroring letters. Each code snippet is accompanied by example inputs and outputs to illustrate their functionality. The examples cover a range of operations such as string transformation and analysis.

Uploaded by

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

35.

Replace vowels, capitalize for ch in S:


consonants, double digits if [Link]():
s = input("Enter string: ") if ch == 'z':
out = "" res += 'a'
for ch in s: elif ch == 'Z':
if [Link]() in 'aeiou': res += 'A'
out += '*' else:
elif [Link](): res += chr(ord(ch) + 1)
out += [Link]() else:
elif [Link](): res += ch
out += str(int(ch) * 2) return res
print(out) print(shiftString("Az9zZ"))
✅ Example Input: ✅ Output:
a1b2c3 Ba9aA
✅ Output:
*2B4C6 39. alternateCase(sentence)
36. Swap every 2 characters in def alternateCase(sentence):
"CBSEExam" result = ""
text = "CBSEExam" upper = True
for i in range(0, len(text), 2): for ch in sentence:
print(text[i:i+2][::-1], end="") if [Link]():
✅ Output: result += [Link]() if upper else
CBSEExam → BCSEaEmx [Link]()
Wait — check carefully: upper = not upper
 "CB" → "BC" else:
 "SE" → "ES" result += ch
 "Ex" → "xE" return result
 "am" → "ma" print(alternateCase("python is fun"))
✅ Final Output: ✅ Output:
BCESxEma PyThOn Is FuN

37. Count palindromic substrings in 40. Words that start and end with same
'madamracecar' letter
s = "madamracecar" sentence = input("Enter a sentence: ")
count = 0 words = [Link]()
for i in range(len(s)): for w in words:
for j in range(i+1, len(s)+1): if w[0].lower() == w[-1].lower():
sub = s[i:j] print(w)
if sub == sub[::-1]: ✅ Example Input:
count += 1 Anna went to level civic racecar
print("Total palindromic substrings:", ✅ Output:
count) Anna
✅ Output: level
Total palindromic substrings: 15 civic
🧠 (Includes: m, a, d, a, m, ada, madam, r, racecar
a, c, e, c, a, r, racecar)

38. Function shiftString(S)


def shiftString(S): 41. Pangram checker
res = "" def isPangram(sentence):
alphabet =
set('abcdefghijklmnopqrstuvwxyz')
return alphabet <= set([Link]())

s = input("Enter sentence: ")


print("Pangram" if isPangram(s) else "Not
a Pangram")
✅ Example Input:
The quick brown fox jumps over the lazy
dog
✅ Output:
Pangram

42. mirrorWord(s)
(A ↔ Z, B ↔ Y, C ↔ X …)
def mirrorWord(s):
res = ""
for ch in [Link]():
if [Link]():
res += chr(155 - ord(ch)) #
65+90=155 → Mirror mapping
else:
res += ch
return res

print(mirrorWord("ABC xyz"))
✅ Output:
ZYX CBA

You might also like