[Tutor] [Re] Fwd: Strings backwards
János Juhász
janos.juhasz at VELUX.com
Thu Jan 19 08:26:14 CET 2006
Hi Ryan,
I just extended Adam's code with a speech-to-text recepi from
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114216.
On 18/01/06, ryan luna <ryan_gm at sbcglobal.net> wrote:
>
> Hello, what i need to do is get user input and then
> print the string backwards ^^ i have no idea how to do
> that,
>
> print "Enter a word and i well tell you how to say it
> backwards"
>
> word = raw_input("Your word: ")
>
> print word
>
> all that is simple enough im sure printing it out
> backwards is to, just dont know how ^^, thanks for any help.
import sys
from win32com.client import constants
import win32com.client
import string
speaker = win32com.client.Dispatch("SAPI.SpVoice")
print "Type word or phrase, then enter."
print "Ctrl+Z then enter to exit."
def backword(word):
l = list(word)
l.reverse()
return ''.join(l)
def backsentence(sentence):
words = sentence.split(' ')
words = [backword(word) for word in words]
return ' '.join(words)
while 1:
try:
s = raw_input()
rev = backsentence(s)
print 'I would say: ', rev
speaker.Speak(rev)
except:
if sys.exc_type is EOFError:
sys.exit()
It works on my xp :)
Yours sincerely,
______________________________
János Juhász
More information about the Tutor
mailing list