简体   繁体   中英

CS50 Readability python, false output

```
from cs50 import get_string

text = get_string("Text: ") 
letters = sentences = 0
words = 1

for i in text:
    if i.isalpha():
        letters += 1
    if i.isspace():
        words += 1
    if i in ['!', '.', '?']:
        sentences += 1
                       
L = (letters / words) * 100
S = (sentences / words) * 100
index = round(0.0588 * L - 0.0296 * S - 15.8)
if index < 1:
    print("Before Grade 1")
elif index >= 16:
    print("Grade 16+")
else:
    print(f"Grade {index}")
```

I'm working on a task of cs50 to make readability in python, but the answer is always not the same as what is written in the manual guide in cs50 website. for example, for input;

Text: Congratulations. Today is your day. You're off to Great Places! You're off and away!

it should print "Grade 3" but instead my code print "Grade 11", I think my code is fine, and the formula I use is in accordance with the guidelines on the website. i tried various solutions related to this on stackoverflow and still didn't get the right answer, what did I do wrong?

Try this:

在此处输入图像描述

PS I get an error when I tried to put the python code in here, that's why I sent a photo!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM