[Tutor] Python backwards program

Jim and Laura Ahl jcahl at psci.net
Wed Apr 13 15:51:25 CEST 2005


Thanks for the encouragement, here is what I have so far.

word=raw_input("Enter a Word or string:")
print word
print word[::-1]
raw_input("\n\nPress the enter key to exit.")

In the print word [::-1] line it gives me this message (sequence index must be an integer)  What does that mean

I have wrote 3 other programs in the class.

A famous quote program where the user inputs their favorite quote, and author and it prints it out.

Two number program the user inputs two numbers and the program adds them together, subtracts, multiply, divide, and hexed.

A fortune cookie program that randomly gives one fortune out of 5 to the user.

Jim
  ----- Original Message ----- 
  From: Feziwe Mpondo 
  To: Alberto Troiano 
  Cc: jcahl at psci.net ; tutor at python.org 
  Sent: Wednesday, April 13, 2005 10:14 AM
  Subject: Re: [Tutor] Python backwards program


  Alberto Troiano wrote:

  > You can do this:
  >
  > >>> word=raw_input("Type the word: ")
  > Type the word: Kokiri Forest
  > >>> print word
  > Kokiri Forest
  > >>> print word[::-1]
  > tseroF irikoK
  >
  > But I saw that this gave you a hard time so this is an alternate 
  > longer way:
  >
  > >>> backword=""
  > >>> counter=len(word)
  >
  > >>> while counter!=0:
  >              backword+=word[counter-1]
  >              counter-=1
  >
  > >>> print backword
  > tseroF irikoK
  >
  > So choose the one you want and feel free to ask in case of any doubt
  >
  > Regards
  >
  > Alberto
  >
  >
  >  Gaucho
  > >From: "Jim and Laura Ahl" <jcahl at psci.net> >To: <tutor at python.org> 
  > >Subject: [Tutor] Python backwards program >Date: Tue, 12 Apr 2005 
  > 20:05:41 -0500 > >I am very new to programming and I have an 
  > assignment to have a raw_input string that is inputted by the user and 
  > then is printed backwards. Can anyone help me? I can get it to print 
  > regular but backwards in not working. > >Thank You >Jim 
  > >_______________________________________________ >Tutor maillist - 
  > Tutor at python.org >http://mail.python.org/mailman/listinfo/tutor
  >
  >------------------------------------------------------------------------
  >
  >_______________________________________________
  >Tutor maillist  -  Tutor at python.org
  >http://mail.python.org/mailman/listinfo/tutor
  >  
  >
  i am able to type, what i can't seem to do is seeing it print or 
  executing the command on the shell window

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050413/2a88e84a/attachment.html


More information about the Tutor mailing list