Question
Paste this code into a new file and find the errors. The most frequent letter in the user_string is H. # Function displays the character
Paste this code into a new file and find the errors. The most frequent letter in the user_string is H.
# Function displays the character that appears most frequently
# in the string. If several characters have the same highest
# frequency, displays the first character with that frequency.
def main():
# Set up local variables
count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
index = 0
frequent = 0
# Receive user input.
user_string = 'Who where what why how'
for ch in user_string:
ch = ch.lower()
# Determine which letter this character is.
index = letters.find(ch)
if index >= 0:
# Increase counting array for this letter.
count[index] = count[index] + 1
for i in range(len(count)):
if count[i] > count[frequent]:
frequent = i
print('The character that appears most frequently' \
' in the string is ', letters[i], '.', \
sep='')
# Call the main function.
main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started