1 00:00:00,300 --> 00:00:06,510 Now, to call this function, we will force to create a list of individual word strings from the string 2 00:00:06,510 --> 00:00:11,970 in the messages, dear, then will convert the string to the uppercase, as we have done here in the 3 00:00:11,970 --> 00:00:12,570 next line. 4 00:00:13,050 --> 00:00:18,720 OK, and then remove the known little characters from the string, such as numbers of punctuation by 5 00:00:18,720 --> 00:00:23,080 calling the remove known little Oresteia method, which we will see later on. 6 00:00:23,100 --> 00:00:23,410 OK. 7 00:00:24,000 --> 00:00:30,420 And after this, finally, we will use a split method that will split the string into individual words 8 00:00:30,420 --> 00:00:33,690 and store them in a variable named possible Monastir. 9 00:00:34,080 --> 00:00:40,620 Not, for example, if the strings, for example, say hi, this is bitin is passed after calling the 10 00:00:40,620 --> 00:00:42,770 get English for count. 11 00:00:43,050 --> 00:00:49,050 OK, the value stored in the variable possible Forestier would be probably see this. 12 00:00:49,330 --> 00:00:51,210 Oh hello space then. 13 00:00:51,210 --> 00:00:55,090 This is there are separate separate vaults which we are creating. 14 00:00:55,350 --> 00:00:59,520 So if the string in the message is made up of integers like say one, two, three, four, five, six, 15 00:00:59,730 --> 00:01:05,130 and the call is made to remove non letters would return a blank string, which splits would be called 16 00:01:05,130 --> 00:01:07,750 on to return an empty string or an empty list. 17 00:01:07,770 --> 00:01:13,900 OK, so in the program, an empty list is basically equivalent to zero volts being English. 18 00:01:14,220 --> 00:01:17,270 This could basically cause and divide by zero error also. 19 00:01:17,610 --> 00:01:22,950 Now let us understand, what is this divide by zero to return of value between zero point zero and one 20 00:01:22,950 --> 00:01:28,710 point zero would divide the number of votes and possible what is still recognized as English by total 21 00:01:28,710 --> 00:01:31,200 number of votes in the possible Forestier. 22 00:01:31,590 --> 00:01:37,020 Now, although this is mostly straightforward, we need to make sure possible votes is not an empty 23 00:01:37,020 --> 00:01:38,720 string of possible votes is empty. 24 00:01:38,730 --> 00:01:44,760 It means total number of votes is basically zero now because in mathematics, dividing by zero has no 25 00:01:44,760 --> 00:01:49,560 meaning, so dividing by zero in between results and an error of divide by zero error. 26 00:01:49,980 --> 00:01:55,410 OK, for example, if we just go to the interactive shell here and we try to do it, something like 27 00:01:55,410 --> 00:02:00,270 42 divided by zero, we get zero divisions, zero error. 28 00:02:00,690 --> 00:02:05,040 OK, now you can see that 42 divided by zero will give you this particular error. 29 00:02:05,340 --> 00:02:10,410 To avoid this will have to make sure that the possible vote lists are still in. 30 00:02:10,410 --> 00:02:11,800 Our list is never empty. 31 00:02:12,150 --> 00:02:15,060 OK, so for that, what are we doing in our program? 32 00:02:15,300 --> 00:02:20,450 If you just check that, if it is empty, we are returning a value zero point zero. 33 00:02:20,820 --> 00:02:26,880 OK, so we are checking the particular list here and if it returns empty, then we are giving a particular 34 00:02:26,880 --> 00:02:29,940 value to it to avoid or divide by zero error in this case. 35 00:02:30,280 --> 00:02:36,540 OK, so now we move on to counting the English word matches now to produce the the of the English of 36 00:02:36,540 --> 00:02:42,900 all three total votes, we will divide the number of votes in the possible vote estimate that are recognized 37 00:02:42,900 --> 00:02:46,740 as English by total number of votes in possible vote SDM. 38 00:02:47,040 --> 00:02:48,000 Now for doing this. 39 00:02:48,000 --> 00:02:52,290 We need to count the number of recognized English words in the possible this. 40 00:02:52,770 --> 00:02:59,400 So we have said the variable match to zero and we use a loop to outrage over each word in the possible 41 00:02:59,400 --> 00:03:00,230 word estimate. 42 00:03:00,600 --> 00:03:04,040 OK, and check whether the vote exists in the English word dictionary. 43 00:03:04,290 --> 00:03:10,800 So that is why we have run this loopier for Wadhawan one in possible Forestier and if word one in English 44 00:03:10,800 --> 00:03:14,970 were tested, then we are putting majesty at plus is equal to one. 45 00:03:15,780 --> 00:03:21,450 After the loop is complete, the number of English words in the string is stored in of the variable. 46 00:03:21,780 --> 00:03:28,170 And remember that we are relying on dictionary fight to be accurate and complete for the English module 47 00:03:28,170 --> 00:03:29,250 to vote correctly. 48 00:03:29,580 --> 00:03:34,650 If a word is in the dictionary file, it won't be counted as English, even if it is a real word. 49 00:03:35,130 --> 00:03:41,250 So conversely, if a word is misspelled in the dictionary, words that are in English might accidentally 50 00:03:41,250 --> 00:03:42,590 become procedural votes. 51 00:03:43,110 --> 00:03:43,840 Not right now. 52 00:03:43,860 --> 00:03:49,530 Number of votes in the possible Forestier that are recognized as English and total number of votes in 53 00:03:49,530 --> 00:03:55,560 the possible Forestier are represented by integers, not the return of load value between zero point 54 00:03:55,560 --> 00:03:56,850 zero and one point zero. 55 00:03:57,060 --> 00:03:58,230 We are dividing this. 56 00:03:58,230 --> 00:04:02,760 Two individuals will return to change one or the other into the floor. 57 00:04:03,090 --> 00:04:10,080 And we are seeing your return flow to Manchester, divided by the length of possible Forestier succumbing 58 00:04:10,080 --> 00:04:15,530 to the flawed interest your functions and the integer division that we have in Python. 59 00:04:15,960 --> 00:04:21,510 Now let's have a look at how to change an integer into a offload, because the two values we will need 60 00:04:21,510 --> 00:04:24,210 to divide to find the ratio are both individuals. 61 00:04:24,420 --> 00:04:30,570 And Python three always does a regular division regardless of of value byte, whereas in Python two, 62 00:04:30,720 --> 00:04:35,340 it performs integer divisions when both values and division operators are integers. 63 00:04:35,700 --> 00:04:42,240 Now, because users might use Python two to import over Shakingly shortly, I will need to pass at least 64 00:04:42,240 --> 00:04:46,710 one integer variable to flow to make sure of Lopez Obrador when doing division. 65 00:04:47,520 --> 00:04:53,850 OK, so doing so, it ensures that regular division will be performed no matter which version of Python 66 00:04:53,850 --> 00:04:54,390 is used. 67 00:04:54,660 --> 00:04:59,460 Now, this is an example of making the code backward compatible with previous versions also. 68 00:04:59,860 --> 00:05:04,660 So although we won't use them in the session, let's review some other functions that converts values 69 00:05:04,660 --> 00:05:05,830 into other types. 70 00:05:06,150 --> 00:05:11,230 We have the end function, which returns an integer version of this argument and the Asgeir function 71 00:05:11,230 --> 00:05:12,290 that returns a string. 72 00:05:12,580 --> 00:05:14,460 Now we'll see how this function works. 73 00:05:14,470 --> 00:05:17,970 Let us into some detail in the interactive shell to get the output. 74 00:05:18,430 --> 00:05:22,390 For example, we enter here and float say forty five. 75 00:05:22,600 --> 00:05:24,120 We get forty five point zero. 76 00:05:24,460 --> 00:05:31,510 We try to enter forty two point zero and convert it to in detail oriented or forty two point five and 77 00:05:31,510 --> 00:05:33,280 get the value of type integer. 78 00:05:33,550 --> 00:05:40,650 Or in that case we say integer forty five and passing the string value to it or we say out of forty 79 00:05:40,660 --> 00:05:41,630 two ok. 80 00:05:41,760 --> 00:05:49,370 Or integer value converting to a string value or if we say fifty six point seven and converting to integer. 81 00:05:49,540 --> 00:05:49,930 OK. 82 00:05:50,140 --> 00:05:56,440 Now you can see that the flawed function changes the integer into a float in function cantando float 83 00:05:56,440 --> 00:05:57,310 to an integer. 84 00:05:57,610 --> 00:06:02,200 My truncating the decimal values all at on string into an integer. 85 00:06:02,590 --> 00:06:06,370 Even the Aschiana function changes numerical values to string values. 86 00:06:06,550 --> 00:06:11,480 So these functions are helpful if you need or values equivalent to be a different data type. 87 00:06:11,860 --> 00:06:15,810 Now coming to finding the ratio of English words in the Methodist idea. 88 00:06:16,030 --> 00:06:21,040 So let's return to our program back and define find the ratio of the English words for total votes. 89 00:06:21,340 --> 00:06:26,890 We then divide the number of matches we found, the total number of possible Modesta so that we are 90 00:06:26,890 --> 00:06:33,070 using the slash order division operator to divide the two numbers again, pretending the value back 91 00:06:33,070 --> 00:06:34,310 to the calling program. 92 00:06:34,660 --> 00:06:40,720 So after we pass the integer matches to the flawed function, it returns the flawed version of that 93 00:06:40,720 --> 00:06:44,350 number, which is divided by the length of the possible Monastir list. 94 00:06:44,920 --> 00:06:50,230 Now, the only way we return the flawed majesty are divided by the length of possible. 95 00:06:50,230 --> 00:06:58,030 Vlasta would lead to divide by zero if the length of possible Forestier is evaluated to zero and the 96 00:06:58,030 --> 00:07:01,690 only way that it would be possible is if possible. 97 00:07:01,700 --> 00:07:03,270 Volesky What an empty list. 98 00:07:03,640 --> 00:07:09,520 However, we have already specified that to check for this case and return zero point zero if it is 99 00:07:09,520 --> 00:07:09,880 empty. 100 00:07:10,270 --> 00:07:14,170 So if possible, wgrz to an empty list program. 101 00:07:14,170 --> 00:07:19,510 Execution would never get past after the particular line that we have told you, OK. 102 00:07:20,430 --> 00:07:26,760 So we can then be confident that this particular division will not cause you or divide by zero error 103 00:07:27,000 --> 00:07:27,770 in this case.