@extends('template') @section('title') Lab 4, Part 4: Text Analysis Program @stop @section('content') # Lab 4, Part 4: Text Analysis In this task, you will write python functions to analyze a given text. Here are some examples: ```py "I love you" 3 words in your text. 8 chars in your text. Most common vowel in your text is "o" ................ "May the odds be ever in your favor" 8 words in your text. 27 chars in your text. Most common vowel in your text is "e" ................ "Be yourself; everyone else is already taken" 7 words in your text. 37 chars in your text. Most common vowel in your text is "e" ................ "Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently. They're not fond of rules. And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them. About the only thing you can't do is ignore them. Because they change things. They push the human race forward. And while some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do" 101 words in your text. 448 chars in your text. Most common vowel in your text is "e" ................ "YYYYYYY" 1 words in your text. 7 chars in your text. Most common vowel in your text is "No vowels present." ................ ``` You need to write one function, say `analyzeText(text)`, that will analyze the given text and print the information shown above. Namely, the number of words and the number of characters in the text are counted and the most common vowel is printed. If there are no vowels, then that is reported. The text is a parameter to the `analyzeText(text)` function. Note that spaces do not count as characters. For counting the words, `split()` might come in handy. **In this task, you have the freedom to structure your solution as you and your partner see best. If you would like some guidance, you can follow the steps below.** ### One suggested strategy #### Step 1\. `letterCount(text,letter)` `letterCount(text,letter)` counts the number of occurences of the given letter in the text. You can use python's built-in `count()` function. Examples: ```py 'pizza'.count('p') ==> 1 'pizza'.count('z') ==> 2 'pizza'.count('k') ==> 0 ``` ```py letterCount("hello there","e") returns 3 letterCount("oh my goodness","e") returns 1 letterCount("oh my goodness","o") returns 3 letterCount("oh my goodness","a") returns 0 ``` #### Step 2\. `maxVowelCount(text)` `maxVowelCount(text)` returns the vowel with the most occurences in the given text. This function uses `letterCount`. Here is an example: ```py maxVowelCount("hello there") returns "e" maxVowelCount("oh my goodness") returns "o" maxVowelCount("CS111") returns "No vowels present" ``` #### Step 3\. `analyzeText(text)` You might find some of the [built-in python functions](https://docs.python.org/2/library/functions.html) useful, as well as [python's string functions](https://docs.python.org/2/library/stri ng.html). ```py text1 = "I love you" analyzeText(text1) ``` produces ```py "I love you" 3 words in your text. 8 chars in your text. Most common vowel in your text is "o" ``` --- ```py text2 = "May the odds be ever in your favor" analyzeText(text2) ``` produces ```py "May the odds be ever in your favor" 8 words in your text. 27 chars in your text. Most common vowel in your text is "e" ``` (see large grey box near top of page for more examples). Note that the `analyzeText()` function requires a string parameter. Later on this semester, you will learn how to write python code to read an entire file. For example, you'll learn how to write programs that, given the name of the file, will open and read all the lines in a file and analyze them. @include('/labs/lab04/_toc') @stop