I’m trying to make a text based game and I want the text to print out slowly to simulate typing. I also want it to be an input. Is it possible to do this?
I saw someone else use this code(bolded is what i added):
import sys,time
def sinput(str):
for c in str + '\n':
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(4./90)
slowtest=sinput('Does it work? ')
**if slowtest == 'yes':
print('Amazing!')**
And it was able to print out the code slowly just like I wanted, unfortunately I can not answer the question ("Does it work?").
>Solution :
You can assign input() to slowtest.
sinput() function is not returning anything.
Once you print slowly you can use input() for slowtest variable then check the if condition.
import sys,time
def sinput(str):
for c in str + '\n':
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(4./90)
sinput('Does it work? ')
slowtest = input()
if slowtest == 'yes':
print('Amazing!')