Not sure what's wrong with this code...

This is the place for queries that don't fit in any of the other categories.

Not sure what's wrong with this code...

Postby KoreanCookie » Mon Apr 21, 2014 5:08 pm

I made a short program that is supposed to print the characters in a string one by one with some delay between each character. So I ended up with this, but when I run this program, I get no result. Nothing is printed on the screen and the program doesn't even end. I would like someone to help with with what I am doing wrong. (Python 3.4)

[EDIT] Okay, I'm still not sure what the problem is, but when I tried it with IDLE it worked for some reason. I think it was there was a bug in the IDE I was using (PyCharm). I guess I'll just use IDLE for now until I know what the problem is.

Code: Select all
import time

def print_pause(text, pause):
    i = 0
    while i < len(text):
        print(text[i], end="")
        i += 1
        time.sleep(0.3)
    time.sleep(pause)

print_pause("What is going on, I don't even... ", 1)
print_pause("Tell me please...", 1)
Last edited by KoreanCookie on Mon Apr 21, 2014 5:32 pm, edited 2 times in total.
KoreanCookie
 
Posts: 3
Joined: Sun Apr 20, 2014 5:45 am

Re: Not sure what's wrong with this code...

Postby stranac » Mon Apr 21, 2014 5:25 pm

Works fine for me, although it doesn't print characters immediately, which is probably what you wanted.
For that, you'll have to use sys.stdout.flush() after your prints.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1245
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: W3C [Linkcheck] and 2 guests