0

In Codewars, question is this: Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.

Examples:

spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" 
spinWords( "This is a test") => returns "This is a test" 
spinWords( "This is another test" )=> returns "This is rehtona test

My code is this:

def spin_words(sentence):
    splited_string = sentence.split(" ")
    empty_string = ""
    for char in splited_string:
        if len(char) >= 5:
            empty_string += char[::-1] + " "
        else:
            empty_string += char + " "
    print(empty_string)

Whenever I test my code on VScode it works perfectly fine.But Codewars didn't accept my code. What is my issue ? Note:I am new at programming and Stackowerflow,If I do something wrong,forgive me.

James Westgate
  • 11,306
  • 8
  • 61
  • 68
Claiz
  • 9
  • 1
    CodeWars has function name as `spinWords` and you have kept your function name as `spin_words`. Try correcting function name and on such platform you should `return` and not `print` – GodWin1100 Jul 30 '22 at 11:42
  • Aside: [Any reason not to use '+' to concatenate two strings?](https://stackoverflow.com/questions/10043636/any-reason-not-to-use-to-concatenate-two-strings) – Nin17 Jul 30 '22 at 11:53

0 Answers0