Created
December 31, 2020 23:12
-
-
Save Edmundworks/4c4266f8747bf3aa47db81e10fa9c323 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cs50 import get_string | |
# Get text from user | |
text = get_string("Text: ") | |
# define variables | |
letters, words, sentences = 0, 1, 0 | |
# Count letters, words and sentences in text | |
for i in range(len(text)): | |
if text[i].lower() in ("abcdefghijklmnopqrstuvwxyz"): | |
letters += 1 | |
if text[i].lower() == " ": | |
words += 1 | |
if text[i].lower() in ("?", "!", "."): | |
sentences += 1 | |
# Define parameters for Coleman-Liau | |
L = (letters / words) * 100 | |
S = (sentences / words) * 100 | |
# Calculate Index per Coleman-Liau | |
index = round(0.0588 * L - 0.296 * S - 15.8) | |
# Print Reading Age | |
if index < 1: | |
print("Before Grade 1") | |
if index > 15: | |
print("Grade 16+") | |
else: | |
print(f"Grade {index}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment