Skip to content
Advertisement

Draw a simple box around a string

I’m trying to learn python, and one of the “tasks” asks me to draw a box around a string. For some reason, I can’t come to a solution. This is supposed to be super basic so we can’t use functions and loops etc.

Here’s the task: (I’m stuck on question 2)

  1. Load a string via the input () function, and stores the result in a variable.

  2. Draw a box around the string. There should be one space before and after the string, and one “=” on each side. Fill in above and below accordingly.

Here’s what it’s supposed to look like:

text: hello

=========
= Hello =
=========

Advertisement

Answer

I think this is what you want:

string = 'Hello'
box_char = '='
print(box_char*(len(string)+4))
print(box_char,string,box_char)
print(box_char*(len(string)+4))
Advertisement