Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do I fix this Python whitespace error?

The instructions state, "For coding simplicity, output a space after every integer, including the last.", but I thought I had already done this with end=' '. What am I doing wrong?

Attachment image

3 Answers

  • 2 months ago

    Use the "sep" parameter.  I.e. "print(n, sep=' ');"  "end" would be at the END, after all parameters, not between any.  Read your textbook.

    Source(s): O'Reilly's "Head First Python"
  • Anonymous
    2 months ago

    autopep8 -i

    Use autopep8

    autopep8 automagically formats Python code to conform to the PEP 8 nullstyle guide. It uses the pep8 utility to determine what parts of the nullcode needs to be formatted. autopep8 is capable of fixing most of the nullformatting issues that can be reported by pep8.

    pip install autopep8

    autopep8 # print only

    autopep8 -i # write file

  • 2 months ago

    What I see is a line with no newline at the end.  That's a possible "whitespace issue" for a robo-grader. 

    Try adding a print() call after the loop ends.  That will certainly end the line and may fix one problem. 

    Another problem is that you will then print a blank line after an error message when n1 > n2.  If that's a test case for your program, then you may have to put the while loop and print() line into an else: block after the if.

Still have questions? Get your answers by asking now.