DEV Community

Cover image for STRING PROBLEMS IN PY
Vinoth Kumar
Vinoth Kumar

Posted on

STRING PROBLEMS IN PY

Q1)

s = 'VINOTH'
word = list(s)

print(word)

key = word[0]
count = 1
i = 1
while i < len(word):
    if key != '*' and key == word[i]:
        word[i] = '*'
        count+=1
    i+=1
print(key, 'is present', count, 'times')
print(word)

Enter fullscreen mode Exit fullscreen mode

Q2)

s = 'VINOTH KUMAR'
word = list(s)

print(word)

key = word[0]
count = 1
i = 1
while i < len(word):
    if key != '*' and key == word[i]:
        word[i] = '*'
        count+=1
    i+=1
print(key, 'is present', count, 'times')
#print(word)

key = word[1]
count = 1
i = 2
while i < len(word):
    if key != '*' and key == word[i]:
        word[i] = '*'
        count+=1
    i+=1
print(key, 'is present', count, 'times')
Enter fullscreen mode Exit fullscreen mode

Q3)

key = word[2]
count = 1
i = 3
while i < len(word):
    if key != '*' and key == word[i]:
        word[i] = '*'
        count+=1
    i+=1
print(key, 'is present', count, 'times')

Enter fullscreen mode Exit fullscreen mode

Top comments (0)