Reputation: 1
My code reads
import time
a = raw_input("Enter a string: ")
b = len(a)
#print 1st letter of string
time.sleep(2)
#print 2nd letter of string
#continue doing that until the last character in the string
What would I need to do to make my code do that in Python 2.7? Prods in the right direction would be much appreciated.
Thank you.
Upvotes: 0
Views: 324
Reputation: 250961
You can iterate over the string itself:
import time
a = raw_input("Enter a string: ")
for char in a: #iterate over string one character at a time
print char
time.sleep(2) # sleep after printing each character
Example:
>>> for x in "foobar":
... print x
...
f
o
o
b
a
r
Upvotes: 1
Reputation: 43495
In [1]: t = 'input string'
In [2]: for c in t:
...: print c
...:
i
n
p
u
t
s
t
r
i
n
g
Upvotes: 0