- 1

How to write a python program to analyze if the letter is in given word or not and to count it?

word=input() letter=input() x=print(len(text)) def count_letter(): Count=0 if letter in text: Count+=1 return count Frequency= print(int(Count/x)*100)

26th Oct 2022, 3:23 AM
Raju Khadka
Raju Khadka - avatar
3 Réponses
+ 4
To check whether a word has a specific letter, use `in` operator if letter in word: # your code To count how many times a letter appear in a word, use count() method of the string class frequency = word.count( letter )
26th Oct 2022, 3:50 AM
Ipang
+ 5
As Ipang mentioned Raju Khadka if letter in word: c = word.count(letter) print(f"the letter {letter} was found {c} times") else: print(f"the letter {letter} was not found")
26th Oct 2022, 4:13 AM
BroFar
BroFar - avatar
+ 2
Thank u I solved the challenge successfully and it goes like this text = input() letter=input() Y=text.count(letter) X=len(text) Frequency=(int(Y)/int(X)*100) print(int(Frequency))
26th Oct 2022, 4:38 AM
Raju Khadka
Raju Khadka - avatar