Python_program 4

 Practical Name: Write a python program to count repeated character in string.

Sample string = ‘INDIA’.

 _______________________________________________________________

Program :                                                                                                                            

 

string = " WELCOME TO INDIA";

print("Duplicate characters in a given string: "); 

for i in range(0, len(string)): 

    count = 1; 

    for j in range(i+1, len(string)): 

        if(string[i] == string[j] and string[i] != ' '): 

            count = count + 1; 

            string = string[:j] + '0' + string[j+1:]; 

     if(count > 1 and string[i] != '0'): 

        print(string[i]," - ",count);

Output:



Post a Comment

Previous Post Next Post