Created
October 16, 2020 05:43
-
-
Save Saarth-Jain/7e211a38e2b1b59f68b70fbf687f5b71 to your computer and use it in GitHub Desktop.
CS50 Solution pset6 readability in python
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 | |
text = get_string("Text: ") | |
numOfLetters = 0 | |
numOfWords = 1 | |
numOfSentences = 0 | |
for i in range(len(text)): | |
if text[i].isalpha(): | |
numOfLetters += 1 | |
elif text[i].isspace(): | |
numOfWords += 1 | |
elif text[i] == '.' or text[i] == '!' or text[i] == '?': | |
numOfSentences += 1 | |
l = numOfLetters / numOfWords * 100 | |
s = numOfSentences / numOfWords * 100 | |
index = 0.0588 * l - 0.29 * s - 15.8 | |
index = round(index) | |
if index > 16: | |
print("Grade 16+") | |
elif index > 1 and index < 17: | |
print(f"Grade {index}") | |
else: | |
print("Before Grade 1") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment