Readability
Implement a program that computes the approximate grade level needed to comprehend some text, per the below.
$ python readability.py
Text: Congratulations! Today is your day. You're off to Great Places! You're off and away!
Grade 3
Specification
- Write, in a file called
readability.py
in~/pset6/readability/
, a program that first asks the user to type in some text, and then outputs the grade level for the text, according to the Coleman-Liau formula, exactly as you did in Problem Set 2, except that your program this time should be written in Python.- Recall that the Coleman-Liau index is computed as
0.0588 * L - 0.296 * S - 15.8
, whereL
is the average number of letters per 100 words in the text, andS
is the average number of sentences per 100 words in the text.
- Recall that the Coleman-Liau index is computed as
- Use
get_string
from the CS50 Library to get the user’s input, andprint
to output your answer. - Your program should count the number of letters, words, and sentences in the text. You may assume that a letter is any lowercase character from
a
toz
or any uppercase character fromA
toZ
, any sequence of characters separated by spaces should count as a word, and that any occurrence of a period, exclamation point, or question mark indicates the end of a sentence. - Your program should print as output
"Grade X"
whereX
is the grade level computed by the Coleman-Liau formula, rounded to the nearest integer. - If the resulting index number is 16 or higher (equivalent to or greater than a senior undergraduate reading level), your program should output
"Grade 16+"
instead of giving the exact index number. If the index number is less than 1, your program should output"Before Grade 1"
.
Usage
Your program should behave per the example below.
$ python readability.py
Text: Congratulations! Today is your day. You're off to Great Places! You're off and away!
Grade 3
Testing
While check50
is available for this problem, you’re encouraged to instead test your code on your own for each of the following.
- Run your program as
python readability.py
, and wait for a prompt for input. Type inOne fish. Two fish. Red fish. Blue fish.
and press enter. Your program should outputBefore Grade 1
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inWould you like them here or there? I would not like them here or there. I would not like them anywhere.
and press enter. Your program should outputGrade 2
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inCongratulations! Today is your day. You're off to Great Places! You're off and away!
and press enter. Your program should outputGrade 3
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inHarry Potter was a highly unusual boy in many ways. For one thing, he hated the summer holidays more than any other time of year. For another, he really wanted to do his homework, but was forced to do it in secret, in the dead of the night. And he also happened to be a wizard.
and press enter. Your program should outputGrade 5
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inIn my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since.
and press enter. Your program should outputGrade 7
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inAlice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice "without pictures or conversation?"
and press enter. Your program should outputGrade 8
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inWhen he was nearly thirteen, my brother Jem got his arm badly broken at the elbow. When it healed, and Jem's fears of never being able to play football were assuaged, he was seldom self-conscious about his injury. His left arm was somewhat shorter than his right; when he stood or walked, the back of his hand was at right angles to his body, his thumb parallel to his thigh.
and press enter. Your program should outputGrade 8
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inThere are more things in Heaven and Earth, Horatio, than are dreamt of in your philosophy.
and press enter. Your program should outputGrade 9
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inIt was a bright cold day in April, and the clocks were striking thirteen. Winston Smith, his chin nuzzled into his breast in an effort to escape the vile wind, slipped quickly through the glass doors of Victory Mansions, though not quickly enough to prevent a swirl of gritty dust from entering along with him.
and press enter. Your program should outputGrade 10
. - Run your program as
python readability.py
, and wait for a prompt for input. Type inA large class of computational problems involve the determination of properties of graphs, digraphs, integers, arrays of integers, finite families of finite sets, boolean formulas and elements of other countable domains.
and press enter. Your program should outputGrade 16+
.
How to Submit
Execute the below, logging in with your GitHub username and password when prompted. For security, you’ll see asterisks (*
) instead of the actual characters in your password.
submit50 cs50/problems/2020/summer/sentimental/readability