Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions