This shouldn't work?

def get_picture(self):
    if self.width > 50 or self.height > 50:
      return "Too big for picture."
      width = "".join(repeat("*",self.width))
      height = "".join(repeat(f"{width}\n",self.height))
      return height

As you can see, in the width variable i repeat the * character as many times as needed and in the height variable i add the newline character and repeat the line as many times as needed.
Logic would dictate the end result of this be something like "**\n**\n". That newline character at the end would make the test fail so i used rstrip() to get rid of it.
Thing is using rstrip() didn’t remove the newline character at the end and removing rstrip() returned the correct result for the test. Does anyone know why this happens?

EDIT: link to the replit: boilerplate-polygon-area-calculator - Replit

But it is expected to have new line character at the end of each line, isn’t it?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Not at the end of the last line i believe

1 Like

get_picture: Returns a string that represents the shape using lines of “". The number of lines should be equal to the height and the number of "” in each line should be equal to the width. There should be a new line (\n) at the end of each line. If the width or height is larger than 50, this should return the string: “Too big for picture.”.

Newline character is expected on every single line, as I read the instructions.

I guess this is a mix of missreading and assuming things from previous challenges on my end then

It seems to be a convention thing.
“a long string on one line”
“a long string/n
over two lines”
The new line is used as a continuation indicator, not as a string terminator.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.