How do I remove this white space in coding?

Write a program that prints a formatted "No parking" sign. Note the first line has two leading spaces.

NO PARKING

1:00 - 5:00 a.m.

Put"NO PARKING\n1:00 - 5:00 a.m." to output

It keeps telling me I have an unexpected space? But I don't understand how to get rid of it.

3 Answers

Relevance
  • VP
    Lv 7
    1 month ago

    1. Which language are you using?

    2. Do you have to cram everything onto 1 line?  

    3. Try splitting up the lines in order to see which part is causing the issue:

    3a. put "  NO PARKING \n"  <--- put 2 spaces in front of NO

    3b. put "1:00 - 5:00 a.m. \n"  <--- end with a \n

    • Login to reply the answers
  • 1 month ago

    It says 'the first line has two leading spaces' implying you should print out two leading spaces at the front, or that you should be trimming off these white spaces? I believe the latter.

    Are you sure your program is actually trimming said spaces? If s = '  NO PARKING\n1:00 - 5:00 a.m.' are you performing a "left strip" (e.g. in Python) to get rid of those leading white spaces?

    That's the only issue I could see happening.

    Try running the program locally with the above 's' I've defined, if your manipulation doesn't yield the proper ouput, at least then you can see what's wrong.

    Another thing to note, are you re-assigning the variable or not?Most functions don't just modify something. E.g. for a string s, s.upper() doesn't modify s, it just returns a copy of s that 'upper'ed that must be stored in a new variable. I.e. z = s.upper()

    • Login to reply the answers
  • 1 month ago

    It would help to say what programming language you are using & what interpreter or compiler etc.

    Offhand I do not know any that take a format such as that & I've been programming for a living for several decades...

    And, Google is not coming up with much that appears related.

    • Login to reply the answers
Still have questions? Get your answers by asking now.