Write program to count number of single character present in one word using python.

Python is one of the very simple or useful language. Here we learn how to Write program to count number of single character present in one word using python. Before we write a program we should understand the logic to make this program.

There is one simple logic or you can say one method of string that is count, count method is used to count number of single characters in string.

In this program we also use index value basically indexing is place value of string it is started from '0',

From reverse order it started from '-1' .

You should also know about loop to perform this practical, in this program we are using while loop

So let start coding…

SOURCE CODE:


name = input("enter your name :")
length = len(name)
i = 0
tem = ""
while i<length:
    if name[inot in tem:
        tem+=name[i]
        c =name.count(name[i])
        print(f"{name[i]}:{c}")
    i+=1

OUTPUT:

enter your name :rajkumar roa
r:3
a:3
j:1
k:1
u:1
m:1
 :1
o:1

ANOTHER OUTPUT:

enter your name :mr programmer boss
m:3
r:4
 :2
p:1
o:2
g:1
a:1
e:1
b:1
s:2

0 Comments