I have been searching for a solution for this error for a while but the solutions that have helped others have not been much help for me.
Here is the code that I've wrote.
def main():
while True:
userInput()
characterCount(userInput)
middleLetter()
spaceCount()
letterReplace()
displayOutput()
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):
characterCount = len(sentence) - sentence.count(' ')
if characterCount < 10:
print('Sorry that is less than 10 letters')
return characterCount
def middleLetter(sentence):
sentence = len(sentence)/2
middleLetter = [sentence +1]
return middleLetter
def spaceCount(sentence):
spaceCount = sentence.count(' ')
return spaceCount
def letterReplace(sentence):
letterReplace= sentence.replace("a", "&")
return letterReplace
def displayOutput(characterCount,middleLetter,spaceCount,letterReplace):
print('Number of letters: '(characterCount))
print('Middle letter: '(middleLetter))
print('Spaces counted: '(spaceCount))
print('Sentence with letter replaced: '(letterReplace))
main()
The problem I have is that when I run the program I get the error.
Traceback (most recent call last):
File "C:UserswoodDesktopSoftware designProgram 4program3_4QuinnWood.py", line 59, in <module>
main()
File "C:UserswoodDesktopSoftware designProgram 4program3_4QuinnWood.py", line 18, in main
characterCount(userInput)
File "C:UserswoodDesktopSoftware designProgram 4program3_4QuinnWood.py", line 32, in characterCount
characterCount = len(sentence) - sentence.count(' ')
TypeError: object of type 'function' has no len()
Most of the times I have seen this error is because of a int being used instead of a string but I can not see what would be causing this error. Any help would be appreciated.
Using some of the given suggestions I have fixed the original error but now when I try to run it I receive the error.
Traceback (most recent call last):
File "C:UserswoodDesktopSoftware designProgram 4program3_4QuinnWood.py", line 59, in <module>
main()
File "C:UserswoodDesktopSoftware designProgram 4program3_4QuinnWood.py", line 22, in main
displayOutput(characterCount,middleLetter,spaceCount,letterReplace)
File "C:UserswoodDesktopSoftware designProgram 4program3_4QuinnWood.py", line 53, in displayOutput
print('Number of letters:'(characterCount))
TypeError: 'str' object is not callable
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…