Home>

I want to make a python program that will run the portal game ending ( https://www.youtube.com/watch?v=Y6ljFaKRTrI& t= 54s) in the console, but for this I need a typing text effect, I'm a beginner and don't know how to do it. i tried using code like this:

import time
text= "h"
print (text, end= '', flush= True)
time.sleep (0.1)
print ('\ b' * len (text) + 'h')
time.sleep (0.1)
print ('\ b' * len (text) + 'he')
time.sleep (0.1)
print ('\ b' * len (text) + 'hel')
print (text, end= '', flush= True)
time.sleep (0.1)
print ('\ b' * len (text) + 'hell')
print (text, end= '', flush= True)
time.sleep (0.1)
print ('\ b' * len (text) + 'hello')
time.sleep (0.1)
print ('\ b' * len (text) + 'hello!')

I've tried using code like this -and? what's wrong?

timur2021-11-25 13:51:10
  • Answer # 1
    import time
    txt= 'text you want'
    for i in txt: # this cycle will take 1 letter from txt
        time.sleep (0.3)
        print (i, end= '', flush= True)
    

    for the output to the line to work as intended, and not immediately write the entire message, you need to addflush= True(I hope you have the latest version of python, the old ones do it differently)

  • Answer # 2
    import time
    txt= 'text you want'
    for i in txt: # this cycle will take 1 letter from txt
        time.sleep (0.3)
        print (i, end= '', flush= True)
    

    for the output to the line to work as intended, and not immediately write the entire message, you need to addflush= True(I hope you have the latest version of python, the old ones do it differently)