I am trying to use a function as a parameter in another function but I keep getting an error. Can you guys please take a look at my code.
#Program used to reverse the order of a string.
sentence = input("Write a sentence. After you click enter it will be returned in reverse order. ")
userInputList = [ ]
reverseInputList = [ ]
#remove any periods from the sentence.
def remove(sentence):
stripped = sentence.replace(".", "")
return stripped
#print string in reverse order
def convertList(stripped):
userInputList = stripped.split()
reverseInputList = userInputList[::-1]
for i in range(len(reverseInputList)):
print (reverseInputList[i], end=" ")
remove(sentence)
convertList(remove())
I don't know want error you get but I see mistake:
you have to assign result from remove(sentence)
to variable and use this result in convertList()
result = remove(sentence)
convertList(result)
or you have to use function with argument remove(sentence)
directly in convertList()
convertList(remove(sentence))
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.