Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Print Rectangle

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Print Rectangle. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Circle's internal status tools use fixed-size text blocks for compact terminal output. Given a rectangle's width and height, return a hollow ASCII rectangle made of * characters, with spaces inside and no trailing newline.

Formal Specification

Implement render_rectangle(width, height). The inputs are positive integers. Return a single string containing exactly height rows, each containing exactly width characters, with rows separated by .

A cell contains * when it lies on the top, bottom, left, or right border. Every other cell contains a space. If either dimension is 1, every position is part of the border.

Constraints

  • 1 <= width <= 100
  • 1 <= height <= 100
  • Both inputs are integers
  • The output has no trailing newline

Function Signature

def render_rectangle(width, height):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output