0

I am making a text based game and I am trying to print this code one character at a time on each column.

'''###############

Let us begin...

###############'''

I can't figure out how to make it come out one column at a time.

Dulnefni
  • 9
  • 2
  • 1
    Possible duplicate of [How to print multiple lines of text with python](https://stackoverflow.com/questions/34980251/how-to-print-multiple-lines-of-text-with-python) – M-- May 11 '19 at 00:35
  • 1
    One line at a time or one column at a time? – Perplexabot May 11 '19 at 00:37

2 Answers2

1

Well, I still felt like answering this despite the vagueness of your question. Maybe this is what you are looking for, this prints one column at a time (one character per row):

import subprocess
import platform
from time import sleep


def clear_screen():
    # thanks to: https://stackoverflow.com/a/23075152/2923937
    if platform.system() == "Windows":
        subprocess.Popen("cls", shell=True).communicate()
    else:
        print("\033c", end="")


# obviously you can create a function to convert your string into this
# list rather than doing it manually like I did, but that is another question :p.
views = ['#\nh\n#', '##\nhe\n##', '###\nhel\n###', '####\nhell\n####', '#####\nhello\n#####']

for view in views:
    clear_screen()
    print(view)
    sleep(0.5)
Perplexabot
  • 1,852
  • 3
  • 19
  • 22
0

If you are already doing print(c, end='') for each character in you string, just add flush=True to the call to print(). The sleep call will introduce enough delay so that you can see the characters print one at a time:

>>> import time
>>> s = '''###############
... Let us begin...
... ###############'''
>>> for c in s:
...    print(c, end='', flush=True)
...    time.sleep(0.1)
PaulMcG
  • 62,419
  • 16
  • 94
  • 130