1 Replies - 392 Views - Last Post: 12 September 2012 - 12:14 PM Rate Topic: -----

#1 Stephenfrazier10  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 109
  • Joined: 12-September 12

Help getting a for loop to go through a work and print it.

Posted 12 September 2012 - 12:07 PM

How would I get a for loop to go through a word that a user entered and print each letter of that word on a single line, with each letter followed by an exclamation mark, and a 1 second time limit?

I got it to work forwardly with this code: So if the user entered Steve as the name it says, S! t! e! v! e!


  for i in name[0:]:
                time.sleep(1)     
                print(i ,end="! ")




I need it to print it out backwards like this. e! v! e! t! s! I know I could get it to print the work backwards by doing this:
 print(lowerName[::-1] + "!")



But I need each letter to be followed by an exclamation mark and each letter to come out 1 second before the next, and ideas?

Everyone's help is appreciated, Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Help getting a for loop to go through a work and print it.

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 756
  • View blog
  • Posts: 1,990
  • Joined: 23-December 08

Re: Help getting a for loop to go through a work and print it.

Posted 12 September 2012 - 12:14 PM

This is great
for letter in name[0:]:
    time.sleep(1)     
    print(letter ,end="! ")

But it could be abbreviated to
for letter in name:
    time.sleep(1)     
    print(letter ,end="! ")




Your issue should be as simple as
for letter in name[::-1]:
    time.sleep(1)     
    print(letter ,end="! ")


This post has been edited by atraub: 12 September 2012 - 12:14 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1