Jump to content

Need help with Python

Go to solution Solved by ZEN,

To make it look more realistic, you could also randomize the sleep-time in between characters:

import timefrom random import randomtext = list("I have been waiting for you")std_slp = 0.2for char in text:    print(char, end="")    var = random()    time.sleep(std_slp*var)
This is in Python 3.3 as I don't know 2.7 so you would have to translate that.
(windows 7) (python 2.7.3)

(really new to python here)

I was wondering how I would make text appear as if it was typed without having to do this:

 

    import time

    time.sleep (0.05)

    print ('I'),

    time.sleep (0.05)

    print (' '),

    time.sleep (0.05)

    print ('h'),

    time.sleep (0.05)

    print ('a'),

    time.sleep (0.05)

    print ('v'),

    time.sleep (0.05)

    print ('e'),

    time.sleep (0.05)

    print (' '),

    time.sleep (0.05)

    print ('b'),

    time.sleep (0.05)

    print ('e'),

    time.sleep (0.05)

    print ('e'),

    time.sleep (0.05)

    print ('n'),

    time.sleep (0.05)

    print (' '),

    time.sleep (0.05)

    print ('w'),

    time.sleep (0.05)

    print ('a'),

    time.sleep (0.05)

    print ('i'),

    time.sleep (0.05)

    print ('t'),

    time.sleep (0.05)

    print ('i'),

    time.sleep (0.05)

    print ('n'),

    time.sleep (0.05)

    print ('g'),

    time.sleep (0.05)

    print (' '),

    time.sleep (0.05)

    print ('f'),

    time.sleep (0.05)

    print ('o'),

    time.sleep (0.05)

    print ('r'),

    time.sleep (0.05)

    print (' '),

    time.sleep (0.05)

    print ('y'),

    time.sleep (0.05)

    print ('o'),

    time.sleep (0.05)

    print ('u'),

    time.sleep (0.05)

    print ('.'),

Link to comment
Share on other sites

Link to post
Share on other sites

The very first thing that comes to mind is create a string and do a loop printing each character and then pausing for that time

Link to comment
Share on other sites

Link to post
Share on other sites

I did something like this a long time ago on a older pc. I'll go look and see if I can find the file

 

EDIT: I'm sorry I can't find the file, but what MikeD suggested should work

i9 25.6 GHz with NeuronThreading, 256gb 6000 MHz RAM, GTX 990 OC 3024MHz 12gb, Skeletal X99 motherboard, 1 Petabyte SSD, Fractal Design Humaniod R1 Case, Herbivore 10,000W PSU, Noctua NF16 LP Derma Cooler.

Probably the only Star Citizen player who is planning on a career in Journalism instead of piracy, mining, trading, exploration, military, station management, etc.

Generation 0: The first time you see this add 1 to the number and copy it into your sig. Consider it a social experiment.

Link to comment
Share on other sites

Link to post
Share on other sites

You want to do something like this, assuming you want to print to a single line

import timeimport sysfor currentChar in "I have been waiting for you":    sys.stdout.write(currentChar)    time.sleep(.05)    sys.stdout.flush()
Link to comment
Share on other sites

Link to post
Share on other sites

To make it look more realistic, you could also randomize the sleep-time in between characters:

import timefrom random import randomtext = list("I have been waiting for you")std_slp = 0.2for char in text:    print(char, end="")    var = random()    time.sleep(std_slp*var)
This is in Python 3.3 as I don't know 2.7 so you would have to translate that.
Link to comment
Share on other sites

Link to post
Share on other sites

Thanks! I ended up using a for loop like this:

 

    greet = ('I have been waiting for you.')
    for x in greet:
        print x,
        time.sleep(0.045)
Link to comment
Share on other sites

Link to post
Share on other sites

Can't seem to quote :/

 

Anyway, the issue with the way you are doing it @AllaboutPC is it will print 'I  h a v e  b e e n...' not 'I have been', I would go with the first way posted, since that will print it correctly

Intel 3570K - MSI GTX 660Ti 3GB OC Edition - 16GB Corsair LP RAM - ASRock Extreme4 Motherboard - Corsair HX850 - Adata Premier Pro SP900 120GB SSD with Windows 7 - Seagate Barracuda 1TD HDD - Seagate Barracuda 500GB HDD - Thermaltake Frio CPU Cooler - CM Storm Enforcer Case - Macbook Pro Early 2011 Laptop

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×