Ad
  • Default User Avatar

    nevermind im sorry fixed the indentation and it worked! ty

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I'm assuming (due to lack of indentation) that you have print(to_weird_case(string)) outside of the function in order to call it. If so, the NameError you encouter is due to you calling to_weird_case() with the parameter string but this variable doesn't exist so you get an error.
    You don't have to include this since the testcases call the function automatically.

    Codewars comments support markdown and html so you are able to section your code which includes indentation using 3 backticks. Use this so that I don't have to manually indentate your code.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    You want it escape route (for it to stop running) to be length of the current recursion equal to 1 since otherwise it will return an empty string("1"[1:] will return an empty string). Change it to len(str) == 1.

    Sorry was going to reply to your comment later since I'm tired.

  • Default User Avatar

    i understand hiding the comment, but atleast provide input seeing as now i cant see my own comment

  • Default User Avatar

    Python:

    def reverse(str):
    if str == "":
    return str
    else:
    return reverse(str[1:]) + str[0]
    print (reverse('Hello World'))

    prints hello world backwards but still gives error:

    Randomly generated tests
    ✔ Test Passed
    ✘ 1 should equal 2

    I have no idea what this means or how to fix it. Any help/suggestions?

  • Default User Avatar

    i am getting the same error and have no idea what it means or how to fix it, my first attempt was this:
    def reverse(str):
    n = 11
    return str[::-1]
    reverse('Hello World')
    got the same error you did. Second attempt was this
    def reverse(str):
    if str == "":
    return str
    else:
    return reverse(str[1:]) + str[0]
    print (reverse('Hello World'))
    now it actualyl prints hello world backwords but says:
    Randomly generated tests
    ✔ Test Passed
    ✘ 1 should equal 2
    not sure where im wrong