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, 23.06.2019 04:31
Type the correct answer in the box. spell all words correctly. the managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
Match the items with their respective descriptions.
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
Visually impaired individuals generally rely on the for navigation. thus, designers need to ensure that mouse-specific inputs, such as pointing, clicking, and hovering, can be done without a mouse.
Answers: 1
question
Computers and Technology, 25.06.2019 01:30
Why is the most liked picture on instagram an eggy? owo
Answers: 1
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, 10.03.2020 18:16
Questions on the website: 13722360