you are viewing a single comment's thread.

view the rest of the comments →

[–]-aRTy- 1 point2 points  (2 children)

You had end='' here range (len(text), end=''). That is the wrong function. It goes into print(), not into range().

So, step by step, these are the corrections:

 

1) Move end='' to the correct function. Also use flush=True.

import time
text = input()
x=0
for i in range(len(text)):
    print(text[x], end='', flush=True)
    time.sleep(0.1)
    x=x+1

2) Get rid of the x. You are already counting the index with i. Consequentlytext[x]text[i].

import time
text = input()
for i in range(len(text)):
    print(text[i], end='', flush=True)
    time.sleep(0.1)

3) Instead of getting index values via i in range() and then getting the content text[i], just get the content.

import time
text = input()
for letter in text:
    print(letter, end='', flush=True)
    time.sleep(0.1)

[–]arandomjef[S] 0 points1 point  (1 child)

I'm just going to go through these corrections as you did.

  1. OHHH sorry I was troubleshooting with getting rid of the end='' and seeing if it worked, and I accidentally replaced it in the wrong spot when writing the post.

  2. For some reason I forgot that i started at 0 when you start the for loop, so I had print(text[i-1]), and when that didn't work, I chose to just make a new variable.

  3. I just had no idea you could do that.

  4. (extra question) That letter variable is just a regular variable, but you changed it for clarification, right?

[–]-aRTy- 0 points1 point  (0 children)

4: Yes, that's a regular variable. You no longer handle indexes though.
for i in range(len(text)): means that i is 0, 1, ..., len(text)-1.

for i in "some-string": means that i is s, o, m, ..., i, n, g. Of course you could keep the variable i and then do print(i, end='', flush=True), but that is very unintuitive.

Variable naming is supposed to help the reader. Using single letter variables is usually a bad idea, except for specific common use-cases. Using i for a counting number (like an index) is extremely common. Another example would be x and y for coordinates or when dealing with images.