Now, to call this function, we will force to create a list of individual word strings from the string
in the messages, dear, then will convert the string to the uppercase, as we have done here in the
next line.
OK, and then remove the known little characters from the string, such as numbers of punctuation by
calling the remove known little Oresteia method, which we will see later on.
OK.
And after this, finally, we will use a split method that will split the string into individual words
and store them in a variable named possible Monastir.
Not, for example, if the strings, for example, say hi, this is bitin is passed after calling the
get English for count.
OK, the value stored in the variable possible Forestier would be probably see this.
Oh hello space then.
This is there are separate separate vaults which we are creating.
So if the string in the message is made up of integers like say one, two, three, four, five, six,
and the call is made to remove non letters would return a blank string, which splits would be called
on to return an empty string or an empty list.
OK, so in the program, an empty list is basically equivalent to zero volts being English.
This could basically cause and divide by zero error also.
Now let us understand, what is this divide by zero to return of value between zero point zero and one
point zero would divide the number of votes and possible what is still recognized as English by total
number of votes in the possible Forestier.
Now, although this is mostly straightforward, we need to make sure possible votes is not an empty
string of possible votes is empty.
It means total number of votes is basically zero now because in mathematics, dividing by zero has no
meaning, so dividing by zero in between results and an error of divide by zero error.
OK, for example, if we just go to the interactive shell here and we try to do it, something like
42 divided by zero, we get zero divisions, zero error.
OK, now you can see that 42 divided by zero will give you this particular error.
To avoid this will have to make sure that the possible vote lists are still in.
Our list is never empty.
OK, so for that, what are we doing in our program?
If you just check that, if it is empty, we are returning a value zero point zero.
OK, so we are checking the particular list here and if it returns empty, then we are giving a particular
value to it to avoid or divide by zero error in this case.
OK, so now we move on to counting the English word matches now to produce the the of the English of
all three total votes, we will divide the number of votes in the possible vote estimate that are recognized
as English by total number of votes in possible vote SDM.
Now for doing this.
We need to count the number of recognized English words in the possible this.
So we have said the variable match to zero and we use a loop to outrage over each word in the possible
word estimate.
OK, and check whether the vote exists in the English word dictionary.
So that is why we have run this loopier for Wadhawan one in possible Forestier and if word one in English
were tested, then we are putting majesty at plus is equal to one.
After the loop is complete, the number of English words in the string is stored in of the variable.
And remember that we are relying on dictionary fight to be accurate and complete for the English module
to vote correctly.
If a word is in the dictionary file, it won't be counted as English, even if it is a real word.
So conversely, if a word is misspelled in the dictionary, words that are in English might accidentally
become procedural votes.
Not right now.
Number of votes in the possible Forestier that are recognized as English and total number of votes in
the possible Forestier are represented by integers, not the return of load value between zero point
zero and one point zero.
We are dividing this.
Two individuals will return to change one or the other into the floor.
And we are seeing your return flow to Manchester, divided by the length of possible Forestier succumbing
to the flawed interest your functions and the integer division that we have in Python.
Now let's have a look at how to change an integer into a offload, because the two values we will need
to divide to find the ratio are both individuals.
And Python three always does a regular division regardless of of value byte, whereas in Python two,
it performs integer divisions when both values and division operators are integers.
Now, because users might use Python two to import over Shakingly shortly, I will need to pass at least
one integer variable to flow to make sure of Lopez Obrador when doing division.
OK, so doing so, it ensures that regular division will be performed no matter which version of Python
is used.
Now, this is an example of making the code backward compatible with previous versions also.
So although we won't use them in the session, let's review some other functions that converts values
into other types.
We have the end function, which returns an integer version of this argument and the Asgeir function
that returns a string.
Now we'll see how this function works.
Let us into some detail in the interactive shell to get the output.
For example, we enter here and float say forty five.
We get forty five point zero.
We try to enter forty two point zero and convert it to in detail oriented or forty two point five and
get the value of type integer.
Or in that case we say integer forty five and passing the string value to it or we say out of forty
two ok.
Or integer value converting to a string value or if we say fifty six point seven and converting to integer.
OK.
Now you can see that the flawed function changes the integer into a float in function cantando float
to an integer.
My truncating the decimal values all at on string into an integer.
Even the Aschiana function changes numerical values to string values.
So these functions are helpful if you need or values equivalent to be a different data type.
Now coming to finding the ratio of English words in the Methodist idea.
So let's return to our program back and define find the ratio of the English words for total votes.
We then divide the number of matches we found, the total number of possible Modesta so that we are
using the slash order division operator to divide the two numbers again, pretending the value back
to the calling program.
So after we pass the integer matches to the flawed function, it returns the flawed version of that
number, which is divided by the length of the possible Monastir list.
Now, the only way we return the flawed majesty are divided by the length of possible.
Vlasta would lead to divide by zero if the length of possible Forestier is evaluated to zero and the
only way that it would be possible is if possible.
Volesky What an empty list.
However, we have already specified that to check for this case and return zero point zero if it is
empty.
So if possible, wgrz to an empty list program.
Execution would never get past after the particular line that we have told you, OK.
So we can then be confident that this particular division will not cause you or divide by zero error
in this case.