Question

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)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#code.py
#Converting string to dictionary
def stringToDict(string):
    d = dict()
    for x in string:
        if not d.get(x):
            d[x] = 1
        else:
            d[x] += 1
    return d

def main():
    string = input("Enter sentence: ").lower()
    maxKey = 0
    maxVal = 0
    d = stringToDict(string)

    #Looping through dictionary and 
    # finding most frequent character from dict
    #Where key is the character value is the count of the charcater in input
    for x in d.keys():
        if(maxVal < d[x]):
            maxVal = d[x]
            maxKey = x
    print("Most frequent character =",maxKey)
    
main()

Output:

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
PYTHON: write a program that lets the user enter a sting and displays te character 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
  • 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...

  • 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

  • Most Frequent Character

    Write a program that lets the user enter a string and displays the character that appears most frequently in the string in addition to the number of times it appeared in the string (without using the 'ord' or 'chr')

  • 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,...

  • Write a C program where user enter a string input, tokenizer the string using space character....

    Write a C program where user enter a string input, tokenizer the string using space character. Calculate the lengh of string. Find word start. Find word end. Count words.

  • (Process a string) Write a program that prompts the user to enter a string and displays...

    (Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{    public static void main (String args[]){        Scanner input = new Scanner(System.in);        System.out.println("Enter a string:");        String ans = input.nextLine();        System.out.println("The string...

  • ***** JAVA ONLY ***** Write a program that asks the user to enter the name of...

    ***** JAVA ONLY ***** Write a program that asks the user to enter the name of a file, 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 file. Use Notepad to create a simple file that can be used to test the program. ***** JAVA ONLY *****

  • Starting out with python 4th edition Write program that lets the user enter in a file...

    Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....

  • write a python program that allows the user to enter two integer values, and displays the...

    write a python program that allows the user to enter two integer values, and displays the results when each of the following arithmetic operators are applied

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