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:
JavaScript
x
6
1
text: hello
2
3
=========
4
= Hello =
5
=========
6
Advertisement
Answer
I think this is what you want:
JavaScript
1
6
1
string = 'Hello'
2
box_char = '='
3
print(box_char*(len(string)+4))
4
print(box_char,string,box_char)
5
print(box_char*(len(string)+4))
6