Paste this code into a new file and find the errors. The most frequent letter in the user_string is H.
# Function displays the character that appears most frequently
# in the string. If several characters have the same highest
# frequency, displays the first character with that frequency.
def main():
# Set up local variables
count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
index = 0
frequent = 0
# Receive user input.
user_string = 'Who where what why how'
for ch in user_string:
ch = ch.lower()
# Determine which letter this character is.
index = letters.find(ch)
if index >= 0:
# Increase counting array for this letter.
count[index] = count[index] + 1
for i in range(len(count)):
if count[i] > count[frequent]:
frequent = i
print('The character that appears most frequently' \
' in the string is ', letters[i], '.', \
sep='')
# Call the main function.
main()
thanks for the question, you need to update two lines. have given my comments and updated the code
======================================================================================
def main():
# Set up local variables
count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
index = 0
frequent = 0
# Receive user input.
user_string = 'Who where what why how'
for ch in user_string:
ch = ch.lower()
# Determine which letter this character is.
# updated the below line, we need to first convert letters to lower case
# only then there will be a match , find() is case sensitive
index = letters.lower().find(ch)
if index >= 0:
# Increase counting array for this letter.
count[index] = count[index] + 1
for i in range(len(count)):
if count[i] > count[frequent]:
frequent = i
# this should be frequent, since the value of frequent is getting updated
# updated the below line
print('The character that appears most frequently in the string is ', letters[frequent], '.',
sep='')
# Call the main function.
main()
=========================================================================================

thanks !
Paste this code into a new file and find the errors. The most frequent letter in the...
Why can't I get this to display the results? def main(): try: string = input('Enter a string: ') #Set Character frequency and occurrence to 0 character_frequency = 0 character_occurrence = 0 #Create loop to count characters for character in string: compare = 0 occurrence = 0 while compare < len(string): if character.lower() == string[compare].lower(): compare += 1 occurrence += 1 if occurrence > character_occurrence and character != '':...
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,...
Background: The first step towards helping someone 'decode' a message is often to count how many times each letter of the alphabet appears in the message. Then divide each count by the total number of letters to compute the relative 'frequency'. From these frequencies, it may be easier to recognize which letters are assigned to the vowels. For your own reference, here is a table of standard letter frequencies from typical English text. (You do NOT need to display this...
JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...
I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...
Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...
In Java, I have created a program which can generate passwords. Currently the program can generate a password through a menu system of which characters to use. To complete the project, I need a system which allows the user to generate another password after the first password is created. I also need a method to check whether or not the password is complex by checking if the generated password has 3 or more character types and then displaying whether or...
I did the assigment but inside mainWrite a C program (called counting.c) that counts the number of characters, words and lines readfrom standard input (stdin) until EOF is reached. This means counting.c must contain a mainfunction along with other function.- Assume the input is ASCII text of any length.-Every byte read from stdin counts as a character except EOF.- Words are defined as contiguous sequences of letters (a through z, A through Z) and the apostrophe ( ' which has...
Debug following methods(longestRun(finds how many times a character got repeated), findLastP(finds last p in a string), findFirstP(finds first p in a string)) in java language. public class simpleLoops { /** * @param args */ public static void main(String[] args) { System.out.println(longestRun("aabbbccd")); System.out.println("Expected 3"); System.out.println(longestRun("aaa")); System.out.println("Expected 3"); System.out.println(longestRun("aabbbb")); System.out.println("Expected 4"); int count = countP("Mississippi"); System.out.println(count); int result = findLastP("Mississippi"); System.out.println(result); result = findFirstP("stop"); System.out.println(result); result = findFirstP("xxxyyyzzz"); System.out.println(result); } /** *...
My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...