1

I receive the test feedback expected "# #\n", not " # # \n" for the test running with n = 1, with the following code snippet called to for printing:

for i in range(n):
    print(
        (n - i) * ' ',
        (i + 1) * "#",
        "  ",
        (i + 1) * "#",
        (n - i) * ' ',
        sep = '', end = "")
    print()

It appears visually perfectly fine in the terminal window, yet the test rejects it as incorrect. Can someone tell me what the issue is? Thanks a ton in advance.

3

This expected "# #\n", not " # # \n" is telling you that there is an extra space in front and an extra space at the end. There should be nothing printed after the final # on a line, so that part should be removed from the program. i in range(n) is 0 indexed. So maximum i will be n - 1, but there should be no leading spaces on the nth line.....

2
  • Thanks for the clarification; I know the spaces aren't supposed to be there. Is there a reason they get included? I tried specifying sep = '' but that clearly didn't help.
    – Ivo
    Feb 16 '19 at 19:41
  • The reason they are included is because the program puts them there. This line (the second one) (n - i) * ' ', adds spaces to the end. This line (the first one) (n - i) * ' ', adds an extra space to the beginning because i is 0 indexed. Feb 16 '19 at 19:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .