Question

CAN ANYONE PLEASE HELP ME SOLVE THIS PROBLEM WITHOUT RETURNING ERRORS, BAD TOKENS, ETC. PLEASE INCLUDE...

CAN ANYONE PLEASE HELP ME SOLVE THIS PROBLEM WITHOUT RETURNING ERRORS, BAD TOKENS, ETC.

PLEASE INCLUDE CORRECT SYNTAX...MUST BE IN PYTHON 3 AND PASS THE TEST

Write a function analyze_text that receives a string as input. Your function should count the number of alphabetic characters (a through z, or A through Z) in the text and also keep track of how many are the letter 'e' (upper or lowercase). Your function should return an analysis of the text in the form of a string phrased exactly like this: “The text contains 240 alphabetic characters, of which 105 (43.75%) are ‘e’.”

USING FUNCTION: def analyze_text(text):

Thank You For Your Help!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python3 Code:

def analyze_text(text):

alphabets = 0 #initializing the count of alphabets as 0

count_e = 0 #initializing the count of 'e's as 0

for i in text: #for every character in text

if(i>='a'and i<='z'): #if character is lowercase alphabet

alphabets+=1 #increasing the count of aplhabets by 1

elif(i>='A'and i<='Z'):#if character is uppercase alphabet

alphabets+=1 #increasing the count of aplhabets by 1

if(i=='e'or i=='E'): #if character is 'E'

count_e+=1 #incrementing the count of 'e's by 1

percentage_of_e = (count_e*1.0/alphabets*1.0)*100.0 #calculating the percentage of es

percentage_of_e = round(percentage_of_e,2) #rounding to 2 decimal places

return "The text contains "+str(alphabets)+" alphabetic characters, of which "+str(count_e)+"("+str(percentage_of_e)+"%) are 'e'."

Screenshot of the code with indentation and it's output in python3 shell:

Add a comment
Know the answer?
Add Answer to:
CAN ANYONE PLEASE HELP ME SOLVE THIS PROBLEM WITHOUT RETURNING ERRORS, BAD TOKENS, ETC. PLEASE INCLUDE...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can...

    Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can be solved in one post so I posted the other on another question so please check them out as well :) Here is the questions in this assignment: Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...

  • Correct the syntax errors to allow the code to pass all of the provided doctests. You...

    Correct the syntax errors to allow the code to pass all of the provided doctests. You may have heard of "Pig Latin," a set of rules for modifying regular English to render it unintelligible to those who do not know the rules. This problem asks you to fix a function that will convert an English word to Pig Latin The rules for converting a word to Pig Latin are as follows: 1. If the word starts with a vowel, add...

  • Please help me with this python3 assignment. Write an iterative function, count_consonants(), that accepts a string...

    Please help me with this python3 assignment. Write an iterative function, count_consonants(), that accepts a string (that can include upper and lowercase characters) and returns the number of consonants in that string. A consonant is defined as any letter in the English alphabet other than the vowels a, e, i, o, u. For example, if you call the function as follows: count_consonants('correct horse battery staple') the function should return 20.

  • I need eclipse code for : Write a program that analyzes text written in the console...

    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...

  • HINT: USE def count_letters function: DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!! use string format to display percentage....

    HINT: USE def count_letters function: DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!! use string format to display percentage. "{:.1f}".format DO NOT USE ROUND PYTHON: Develop a program that asks the user to enter a text. The program should analyze the text and print out unique letters, in alphabetical order, with the percentage information of each letter. Case should be ignored. Write a function to analyze the text string. No global variables are used in the function. Function parameters must be used. Hint:...

  • Can anyone help me to solve this problem? Thanks in advance Assignment 6 Strings Write a...

    Can anyone help me to solve this problem? Thanks in advance Assignment 6 Strings Write a program which makes Caesar encryption. Caesar encryption is based on circular shifting of the letters with a given amount. Your program will encrypt the input and it will shift the letters by the given amount (if it passes z, it will continue from a), it will not change spaces (" "). You can assume that no other characters will be entered.

  • I'm a bit confused on how to get this program to run right. Here are the...

    I'm a bit confused on how to get this program to run right. Here are the directions: Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘  ‘This line has extra space characters’ Function name: reduceWhitespace Number of parameters: one string line Return value: one string line The main file should handle the...

  • use python IDEL Please highlight the answer Problem 1 Errors and Exceptions. There are two main...

    use python IDEL Please highlight the answer Problem 1 Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...

  • [3] In python, please help me write the functions needed for this problem: Another Way to do Parentheses: For this probl...

    [3] In python, please help me write the functions needed for this problem: Another Way to do Parentheses: For this problem, you will be given a string that contains parentheses, brackets, and curly braces ( (, ), [, ], {,} ) and other characters. As a human you are given a string of any characters, determine if the parentheses, brackets, and braces match. (No trailing or leading parentheses). The function called on an empty string will return True. Parentheses must...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT