Computer Science, asked by ahad999, 10 months ago

write a python program to input a string and from given string find the occurrence of the first alphabet of the string

Ans fast
First correct answer would be marked as brainlist

Answers

Answered by Equestriadash
8

string = input("Enter a string: ")

ch = string[0]

count = 0

for i in string:

 if i == ch:

   count = count + 1

print(ch, "appears in", string, count, "times.")

The first character can be obtained by using positive indexing.

You then start a loop, that traverses through the string and checks if the first character is present in the string or not and counts the number of times it occurs in it.

Attachments:
Answered by viji18net
2

Answer:

string = input("Please enter your own String : ")  

char = input("Please enter your own Character : ")  

count = 0  

for i in range(len(string)):  

 if(string[i] == char):  

   count = count + 1  

print("The total Number of Times ", char, " has Occurred = " , count)

Similar questions