第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

cs50 pset6 可讀性得到錯(cuò)誤等級(jí)和負(fù)索引

cs50 pset6 可讀性得到錯(cuò)誤等級(jí)和負(fù)索引

米琪卡哇伊 2022-10-11 21:16:56
誰(shuí)能發(fā)現(xiàn)這個(gè)問題?每次我的索引都為負(fù)數(shù),所以它總是打印“Before Grade 1”。我嘗試做一些正則表達(dá)式,但我仍然不知道如何真正實(shí)現(xiàn)它import refrom cs50 import get_stringwords = 1letters = 0sentences = 0st = get_string("Text: ")t = len(st)regex = r'\w+'output = re.findall(regex,st)for i in range(t):    if st.isalpha():        letters += 1    if st.isspace():        words += 1    if st[i] == '.' or st[i] == '!' or st[i] == '?':        sentences += 1L = (letters / words * 100)S = (sentences / words * 100)index = 0.0588 * L - 0.296 * S - 15.8roundedIndex = round(index)if roundedIndex < 1:    print("Before Grade 1")if roundedIndex >= 16:    print("Grade 16+")else:    print(roundedIndex)
查看完整描述

1 回答

?
慕妹3146593

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊

在您的循環(huán)中,您正在檢查整個(gè)字符串是按字母順序排列還是空格,而不是與索引對(duì)應(yīng)的字母是否i是。你可能想要st[i].isalpha()和st[i].isspace().


或者,您可以直接遍歷字符,而不是遍歷索引:


for char in st:

    if char.isalpha():

        ...

    if char.isspace():

        ...


查看完整回答
反對(duì) 回復(fù) 2022-10-11
  • 1 回答
  • 0 關(guān)注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)