0
print("""
     _^__^_
     |°  °|
    _|\__/|_
   /       \\
  /   {}   \\
 / |        |\\
   |________|
   |   __   |
   |  /  \\  |
   |__|  |__|
    vv    vv

""".format(str(input("Enter text to show: "))))

this is the code can anyone suggest me a code to adjust the size of the ascii chracter?

  • Does this answer your question? [How can I fill out a Python string with spaces?](https://stackoverflow.com/questions/5676646/how-can-i-fill-out-a-python-string-with-spaces) – Yevhen Kuzmovych Feb 12 '23 at 14:15

2 Answers2

1

you can use the str.ljust method of string, and put it into a function for convenience

template = """
     _^__^_
     |°  °|
    _|\__/|_
   /       \\
  /   {}\\
 / |        |\\
   |________|
   |   __   |
   |  /  \\  |
   |__|  |__|
    vv    vv

"""

def fun(text):
    print(template.format(text.ljust(9)))

and a quick test

>>> fun("0")

     _^__^_
     |°  °|
    _|\__/|_
   /       \
  /   0     \
 / |        |\
   |________|
   |   __   |
   |  /  \  |
   |__|  |__|
    vv    vv


>>> fun("420")

     _^__^_
     |°  °|
    _|\__/|_
   /       \
  /   420   \
 / |        |\
   |________|
   |   __   |
   |  /  \  |
   |__|  |__|
    vv    vv

>>> fun("hello")

     _^__^_
     |°  °|
    _|\__/|_
   /       \
  /   hello \
 / |        |\
   |________|
   |   __   |
   |  /  \  |
   |__|  |__|
    vv    vv

additionally you can mix it with str.rjust so it can move to the other side, and even truncate if it is too long with some slice notation

template = """
     _^__^_
     |°  °|
    _|\__/|_
   /       \\
  /{}\\
 / |        |\\
   |________|
   |   __   |
   |  /  \\  |
   |__|  |__|
    vv    vv

"""

def fun(text):
    print(template.format(text[:9].ljust(6).rjust(9)))

a quick test

>>> fun("a")

     _^__^_
     |°  °|
    _|\__/|_
   /       \
  /   a     \
 / |        |\
   |________|
   |   __   |
   |  /  \  |
   |__|  |__|
    vv    vv


>>> fun("hello")

     _^__^_
     |°  °|
    _|\__/|_
   /       \
  /   hello \
 / |        |\
   |________|
   |   __   |
   |  /  \  |
   |__|  |__|
    vv    vv


>>> fun("abracadabra")

     _^__^_
     |°  °|
    _|\__/|_
   /       \
  /abracadab\
 / |        |\
   |________|
   |   __   |
   |  /  \  |
   |__|  |__|
    vv    vv

there is also str.center, which is another one you can play with...

Copperfield
  • 8,131
  • 3
  • 23
  • 29
0

you can try to change the format to save the string in a value and use the string length len(string) to add spaces dynamically through the * operation: "_"*len(string).

now you just need to figure out the proper proportions of your character and add the dynamic characters accordingly.

string = str(input("Enter text to show: ")) 

print("""
     _^__^_
     |°  °|
    _|\__/|_{1}
   /       \\
  /   {0}   \\
 / |        |\\
   |________|
   |   __   |
   |  /  \\  |
   |__|  |__|
    vv    vv

""".format(string, "__"*len(string) ) )
Rama Salahat
  • 182
  • 12