Readability
Problem to Solve
Write, in a file called readability.py
in a folder called sentimental-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.
Demo
Specification
- 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. - 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"
.
How to Test
While check50
is available for this problem, you’re encouraged to first 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+
.
Correctness
check50 cs50/problems/2023/fall/sentimental/readability
Style
style50 readability.py
How to Submit
Per Step 4 below, after you submit, be sure to check your autograder results. If you see SUBMISSION ERROR: missing files (0.0/1.0)
, it means your file was not named exactly as prescribed (or you uploaded it to the wrong problem).
Correctness in submissions entails everything from reading the specification, writing code that is compliant with it, and submitting files with the correct name. If you see this error, you should resubmit right away, making sure your submission is fully compliant with the specification. The staff will not adjust your filenames for you after the fact!
- Download your
readability.py
file by control-clicking or right-clicking on the file in your codespace’s file browser and choosing Download. - Go to CS50’s Gradescope page.
- Click Problem Set 6: Sentimental (Readability).
- Drag and drop your
readability.py
file to the area that says Drag & Drop. Be sure it has that exact filename! If you upload a file with a different name, the autograder likely will fail when trying to run it. Ensuring you have uploaded files with the correct filename is your responsibility! - Click Upload.
You should see a message that says “Problem Set 6: Sentimental (Readability) submitted successfully!”