Question: Write this program in python: //creating an array of all letters: uppercase and lowercase char letters[52] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',

Write this program in python:

//creating an array of all letters: uppercase and lowercase char letters[52] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

int main(void) { //start the number of word from 1, and the rest from 0 int nbL = 0; int nbW = 1; int nbS = 0; //asks the user to input a text string text = get_string("Text: "); //using a for loop to count all letters, words, and sentences according to the lenght of the text for (int i = 0, n = strlen(text); i < n; i++) { //if the text is between array number 0 and 25 or between 26 and 51 then count number of letters if ((text[i] >= (char) letters[0] && text[i] <= (char) letters[25]) || (text[i] >= (char) letters[26] && text[i] <= (char) letters[51])) { nbL++; } //if text has a space ' ', then count number of words else if (text[i] == ' ') { nbW++; } //if text has '!', '.', or '?', then count number of sentences else if (text[i] == '!' || text[i] == '.' || text[i] == '?') { nbS++; } } //L is the average number of letters per 100 words in the text float L = (100 * (float) nbL / (float) nbW); //S is the average number of sentences per 100 words in the text. float S = (100 * (float) nbS / (float) nbW); //Recall that the Coleman-Liau index is computed using the formula: float index = 0.0588 * L - 0.296 * S - 15.8; //if index is greater or equal than 16, print grade 16+ if (index >= 16) { printf("Grade 16+ "); } //else if index is less or equal than 1, print before grade 1 else if (index <= 1) { printf("Before Grade 1 "); } //if index is greater or equal than 0, and index is less than 16, print grade as an int (round the index to get the grade) else if (index >= 0 && index < 16) { printf("Grade %i ", (int) round(index)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!