subject
Computers and Technology, 04.01.2021 02:50 sksksjs

Python - write a program that lets the user enter a string and displays the character that appears most frequently in the string. This is my attempt so far, I know it needs a lot of changes:

# This program has the user enter a string and displays the
# character that appears most frequently in the string.

def main():
# Create a variable to use to hold the count.
# Start the variable with 0.
count = 0

# Have the user enter a string.
my_string = input('Enter a sentence: ')

# Count the character that appears most frequently in the string.
for ch in my_string:
if ch == 'A' or ch == 'a':
count+=1
if ch == 'B' or ch == 'b':
count+=1
if ch == 'C' or ch == 'c':
count+=1
if ch == 'D' or ch == 'd':
count+=1
if ch == 'E' or ch == 'e':
count+=1
if ch == 'F' or ch == 'f':
count+=1
if ch == 'G' or ch == 'g':
count+=1
if ch == 'H' or ch == 'h':
count+=1
if ch == 'I' or ch == 'i':
count+=1
if ch == 'J' or ch == 'j':
count+=1
if ch == 'K' or ch == 'k':
count+=1
if ch == 'L' or ch == 'l':
count+=1
if ch == 'M' or ch == 'm':
count+=1
if ch == 'N' or ch == 'n':
count+=1
if ch == 'O' or ch == 'o':
count+=1
if ch == 'P' or ch == 'p':
count+=1
if ch == 'Q' or ch == 'q':
count+=1
if ch == 'R' or ch == 'r':
count+=1
if ch == 'S' or ch == 's':
count+=1
if ch == 'T' or ch == 't':
count+=1
if ch == 'U' or ch == 'u':
count+=1
if ch == 'V' or ch == 'v':
count+=1
if ch == 'W' or ch == 'w':
count+=1
if ch == 'X' or ch == 'x':
count+=1
if ch == 'Y' or ch == 'y':
count+=1
if ch == 'Z' or ch == 'z':
count+=1
#Print the result.
print('The most popular character appears ', count, 'times.')

# Call the main function.
main()

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:00
You turn your computer on and the computer will not boot up where is something you should do to diagnose the problem?
Answers: 1
question
Computers and Technology, 23.06.2019 21:00
Will this setup result in what kathy wants to print?
Answers: 2
question
Computers and Technology, 23.06.2019 23:40
4. what is the reason for including the following code snippet in the header file animal.h? #ifndef animal_h #define animal_h class animal { public: animal(); animal(double new_area_hunt); void birth(); void hunt(double new_area_hunt); void death(); double get_area_hunt() const; private: double area_hunt; }; #endif
Answers: 3
question
Computers and Technology, 24.06.2019 10:00
Which feature of a blog to restore and retrieve older post
Answers: 3
You know the right answer?
Python - write a program that lets the user enter a string and displays the character that appears m...
Questions
question
Mathematics, 08.12.2020 14:00
question
Mathematics, 08.12.2020 14:00
question
Mathematics, 08.12.2020 14:00
question
Mathematics, 08.12.2020 14:00
Questions on the website: 13722367