Question

Python: Write a program that lets the user enter a string and displays the letter that...

Python:

Write a program that lets the user enter a string and displays the letter that appears most frequently in the string, ignore spaces, punctuation, and Upper vs Lower case.

Create a list to hold letters based on the length of the user input

Convert all letters to the same case

Use a loop to check for each letter in the alphabet

Have a variable to hold the largest number of times a letter appears, and replace the value when a higher number is found

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is code:

#initially added 26 letter array

count = [0] * 26

#read input

str = input("Enter a string : ")

#loop the string

for i, c in enumerate(str):

if(c.isalpha()):

#find index of character find the index a = 0 , b= 1,c = 2 ..... z = 26

index = ord(c.lower()) - 97

# increment the value of index

count[index] = count[index] + 1

max = 0

#find max index value

for i in range(26):

if(count[max] < count[i]):

max = i

print("The max time character occurred is : ",chr(max + 97))

#initially added 26 letter array count [0] * 26 #read input str-input (Enter a string) #loop the string for i, c in enumerat

Output:

Enter a string sample@ string The max time character occurred iss

Add a comment
Know the answer?
Add Answer to:
Python: Write a program that lets the user enter a string and displays the letter that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is python do it in pycharm Programming Practice 8.3: Most Frequent Character 15 pts Not...

    this is python do it in pycharm Programming Practice 8.3: Most Frequent Character 15 pts Not Submitted Due Mar 15, 2020 at 11:59 PM Submission Types Website URL Grade O Out of 15 pts Points Submission & Rubric Description Lesson Objective(s): • Use the .upper function • Use loops with strings • Use lists with strings Lesson: Write a program that lets the user enter a string and displays the letter that appears most frequently in the string. Ignore spaces,...

  • PYTHON: write a program that lets the user enter a sting and displays te character that...

    PYTHON: write a program that lets the user enter a sting and displays te character that appears most frequently in the string. A space can be the most frequent in the string, but do not include it for the count. (Please make it as simple as possible, I just started learning python)

  • PYTHON You are to write a program that will analyze the frequency of letters in a...

    PYTHON You are to write a program that will analyze the frequency of letters in a string. The user will enter a string, your program will output the number of times the letters of the alphabet appear in that string. The user is to enter a string that has upper or lower case letters only, no spaces or other characters. You should convert the string entered to all lowercase letters before you conduct your analysis.

  • USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to enter a “special”...

    USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to enter a “special” letter. The program should then ask the user to enter a single line sentence containing all lowercase letters and no punctuation, except for a period at the end. The program will then output the number of times that this letter appears in the sentence. Example: Enter a special letter: t Enter a sentence: here is my little sentence. Your letter appears 3 times. (t...

  • Answer in python please and use loop Question 2: Write a program that prompts the user...

    Answer in python please and use loop Question 2: Write a program that prompts the user to enter a sentence string. The program will either print True if the sentence contains every letter of the alphabet. If the sentence does not contain each letter, print which letters are missing. The results should not depend on capitalization. Hint: a loop may be very handy in the solution.

  • Write a program in python that asks the user to input a sentence. The program will...

    Write a program in python that asks the user to input a sentence. The program will ask the user what two letters are to be counted. You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence. You are not allowed to use python built-in function "count()" or you'll get a Zero! Output will show the sentence, the letter, and the number of times the letter appears in...

  • Write a program that prompts the user to enter a file name and displays the occurrences...

    Write a program that prompts the user to enter a file name and displays the occurrences of each letter in the file. Letters are case-insensitive. Here is a sample run: Enter a filename: Lincoln.txt Number of A’s: 23 Number of B’s: 0 Number of C’s: 12 …… Number of Y’s: 5 Number of Z’s: 7

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • Design a program that prompts the user to enter a string, and displays the character that...

    Design a program that prompts the user to enter a string, and displays the character that appears most frequently in the string. (Please read the problem above carefully. I'm asking this question for the second time because the last answer I received wasn't even paying attention to what the question asked for.) Answer MUST be using Flowgorithm with screenshots. Please attach a screenshot of the program successfully running in flowgorithm as well to confirm proper output. Thanks for understanding!

  • Write a program that asks the user to enter a string and then asks the user...

    Write a program that asks the user to enter a string and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. python programming

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT