-2
我一直堅持處理python中的錯誤,並一直在尋找一段時間來修復它,但無濟於事。錯誤:'str'對象不可調用python
這裏是我得到
Traceback (most recent call last):
File "C:\Users\wood\Desktop\Software design\Program 4\program3_4QuinnWood.py", line 62, in <module>
main()
File "C:\Users\wood\Desktop\Software design\Program 4\program3_4QuinnWood.py", line 23, in main
displayOutput(letterCount,middleCharacter,spaceAmount,aReplace)
File "C:\Users\wood\Desktop\Software design\Program 4\program3_4QuinnWood.py", line 56, in displayOutput
print('Number of letters:'(letterCount))
TypeError: 'str' object is not callable
這是迄今爲止我所編寫的代碼錯誤。
def main():
while True:
sentence= userInput()
letterCount= characterCount(sentence)
middleCharacter= middleLetter(sentence)
spaceAmount= spaceCount(sentence)
aReplace= letterReplace(sentence)
displayOutput(letterCount,middleCharacter,spaceAmount,aReplace)
def userInput():
sentence = str(input('Enter a sentence at least 10 letters long, or type STOP to quit:'))
if sentence == 'STOP':
quit()
return sentence
def characterCount(sentence):
letterCount = len(sentence) - sentence.count(' ')
if letterCount < 10:
print('Sorry that is less than 10 letters')
def middleLetter(sentence):
sentence = len(sentence)/2
middleCharacter = [sentence +1]
def spaceCount(sentence):
spaceAmount = sentence.count(' ')
def letterReplace(sentence):
aReplace= sentence.replace("a", "&")
def displayOutput(letterCount,middleCharacter,spaceAmount,aReplace):
print('Number of letters:'(letterCount))
print('Middle letter:'(middleCharacter))
print('Spaces counted:'(spaceAmount))
print('Sentence with letter replaced:'(aReplace))
main()
該解決方案可能是簡單的,我俯瞰,但任何幫助,將不勝感激。
相關:https://stackoverflow.com/questions/47363786/object-of-type-function-has-沒有-LEN-中的Python / – bhansa