I’m trying to learn Python. One of the tasks is to make a box with a dynamic box.
Here’s an example of how it’s supposed to work:
text: ertioe integer: 40 ======================================== = ertioe = ========================================
Here’s my code:
print("write in something: ") string = str(input()) print("write in a integer: ") integer = float(input()) symbol = '=' print(symbol* (int(integer)+4)) print(symbol, string, symbol) print(symbol* (int(integer)+4))
My box is all wrong:
Advertisement
Answer
You just need to centre align your string to the correct width, replace the middle print statement with:
print(symbol, string.center(int(integer)), symbol)
Edit:
Also, in case you aren’t aware, you can put the print statements within the input()
:
string = str(input("write in something: ")) integer = float(input("write in a integer: "))