Ad
  • Custom User Avatar

    Python won't display a single output on seperate lines unless a string spefically contains a line break, you can't tell seperate array elements to display on seperate lines in a single return.

    To get the function to return the tower with the breaks already included, you will have to turn it in to a string.

    return "\n".join(tower)
    

    Otherwise when calling the function you will need to do something along the lines of this, to make each floor display on its own line.

    for floor in tower_builder(10):
      print(floor)
    
  • Custom User Avatar

    Because the string is empty, nothing is displayed in console. That's a subtle hint to pick up on that input could be empty - if other inputs are logged successfully.

  • Custom User Avatar

    Oops I thought I blurred out the code when uploading the screenshot, my bad! I understand the error message but why doesn't it tell me the value of an input string with which the code failed? It would've been easier if it said that it showed that the code failed when the input was an empty string.

  • Custom User Avatar

    By the way, the error message even pinpoints the exact line that fails. Try to think what input would crash your program if you try accessing 0th element.

  • Custom User Avatar

    Can you read, sir? :P

    The error message is right in front of you, in console output:

    IndexError: string index out of range

    Which means you tried accessing a character that was out of string's bounds. Use print() statements and try to debug your code.

    Because you posted a screenshot containing your code, I have to mark your post a spoiler. Keep in mind that you can post your code here in discourse, using proper formatting (for next time)

  • Custom User Avatar

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

  • Custom User Avatar

    I've implemented my solution with Python and the function returns a list which has passed all tests, however, each "floor" of the tower is displayed in the same line when I run this function.

    How can I adjust the code so that each floor (list item) gets displayed in a separate line, while still returning a function (rather than turning a list into a string consisting of line items)?