forked from shikaruki/Hactoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Occurrence.py
31 lines (22 loc) · 851 Bytes
/
Occurrence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
while (True):
word = input("Enter a word : ")
# Loop to retrieve the words of the word/sentence
letters_in_word = []
for letter in word:
if (letter not in letters_in_word):
letters_in_word.append(letter.lower())
# Loop to count occurrences of the letter
letters_with_occurrence = []
for letter in letters_in_word:
occ = 0
for occurrence in word:
if (occurrence.lower() == letter):
occ += 1
letters_with_occurrence.append((letter, occ))
for occurrence in letters_with_occurrence:
print(occurrence[0] +" appears "+ str(occurrence[1]) +" time(s)")
retry = input ("Do you want to continue ? (Y/N): ")
if (retry in ("y", "Yes", "Y")):
continue
else:
break