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)
Load a string via the input () function, and stores the result in a variable.
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))