Simple Apps written in Python
1) This Program is designed to count character occurrences in a given word, phrase or sentence.
If the word is empty, then "The chosen word is empty" will be printed out, if not, then it will check if you have chosen any letter to check its occurrence in the word and print out the final result, and you did not choose any letter the program will show the count the occurrences of the for each letter in the chosen word.
def count_char(word, char = ''):
if word == '':
print('The chosen word is empty')
else:
word = word.lower()
if char == '':
print('since you did not specify and enter any character to be counted, so here is the count of the occurrences of the all characters in your chosen word.')
output = {}
for i in word:
if i in output:
output[i] += 1
else:
output[i] = 1
print(output)
else:
char = char.lower()
count = 0
for i in word:
if i == char:
count += 1
print('The char {} has been found in this word {} {} times.'.format(char, word, count))