這可能是一個愚蠢的問題;也許我的過程完全錯誤(如果是,請指出),但是如何在自定義函數中提取三個遞增變量(c_char、c_word、c_sentence)并將其用于其他用途?def length_finder(x): #variables counting character,word,sentnece c_char = 0 c_word = 1 c_sentence = 0 for i in x: if (i >= 'a' and i <= 'z') or (i >= 'A' and i <= 'Z'): c_char += 1 if i == " ": c_word += 1 if i == '.' or i == '!' or i == '?' : c_sentence += 1length_finder(input("Enter the text you wish to analyze: "))L = 100/c_word*c_charS = 100/c_word*c_sentence#formula to get readabilityindex = 0.0588 * L - 0.296 * S - 15.8print("This text is suitable for grade " + str(index))
如何在 python 函數之外使用遞增變量?
慕婉清6462132
2022-10-06 19:34:57