Question: The problem is: Write a program that lets the user enter a string and displays the character that appears most frequently in the string. If
The problem is: Write a program that lets the user enter a string and displays the character that appears most frequently in the string. If there is a tie, it must display all the letters.
The code works when there's one letter, but only displays one when there are more than one letter that has the same frequency. I need the code to show all the letters. Note: it has to be Python 3
def main():
string = input('Enter a string: ')
string.lower()
count = 0 total_count = 0
most_frequent_letter = ""
for ch in string: for str in string: if str == ch: count += 1 if count > total_count: total_count = count most_frequent_letter = ch counter = 0
print("The most frequently occuring letter(s): " , most_frequent_letter)
main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
