Computers and Technology
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()

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 12:40, dkjfghdjk
In a response of approximately 50 words, explain why it would be essential for the successful a/v technician to participate in additional coursework, presentations and seminars offered by equipment manufacturers as well as annual conferences attended by colleagues in the industry.
Answers: 1
image
Computers and Technology, 22.06.2019 19:30, Jbutler15
When creating a presentation in libre office impress, where does the editing of slides take place?
Answers: 1
image
Computers and Technology, 23.06.2019 23:30, cam961
What are "open-loop" and "closed-loop" systems
Answers: 1
image
Computers and Technology, 24.06.2019 00:00, Amrinderkhattra
Visualizing a game of “tag” to remember the meaning of contagious
Answers: 3
Do you know the correct answer?
Python - write a program that lets the user enter a string and displays the character that appears m...

Questions in other subjects:

Konu
Advanced Placement (AP), 24.07.2019 07:00