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

    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)