I'm having a problem with my program that is supposed to reverse the string by using a function that takes the first word of a string and a function that prints the string without the first word.
def first_word(string):
first_space_pos = string.find(" ")
word = string[0:first_space_pos]
print(word)
def last_words(string):
first_space_pos = string.find(" ")
words = string[first_space_pos+1:]
print(words)
def reverse(string):
words = string.count(" ") +1
count = 1
string_reversed = ""
while count < words:
string_reversed = first_word(string) + str(" ") + string_reversed
string = last_words(string)
count += 1
print(string_reversed)
The error I'm getting is:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
and it's for this line:
string_reversed = first_word(string) + str(" ") + string_reversed
Any help is appreciated. Thanks.