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 22:00
Which is produced by the endocrine system to control how cells and organs function
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
What is the digital revolution and how did it change society? what are the benefits of digital media?
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
How to do this programming flowchart?
Answers: 3
question
Computers and Technology, 24.06.2019 08:30
@josethesolis i need can anyone text me and follow me
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, 20.09.2020 18:01
question
Mathematics, 20.09.2020 18:01
question
Geography, 20.09.2020 18:01
question
Mathematics, 20.09.2020 18:01
question
Business, 20.09.2020 18:01
question
Mathematics, 20.09.2020 18:01
Questions on the website: 13722363