0

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.

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0
In [1]: t = 'input string'

In [2]: for c in t:
   ...:     print c
   ...:     
i
n
p
u
t

s
t
r
i
n
g

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.