[Tutor] Help Needed
Albert-jan Roskam
fomcl at yahoo.com
Tue Jun 16 14:04:42 CEST 2009
Hi,
This is how I would do it, although there might be more readable solutions:
s = raw_input("Enter a message: ")
print "".join([s[-letter] for letter in range(len(s)+1)])
Cheers!!
Albert-Jan
--- On Tue, 6/16/09, Alan Gauld <alan.gauld at btinternet.com> wrote:
> From: Alan Gauld <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Help Needed
> To: tutor at python.org
> Date: Tuesday, June 16, 2009, 1:57 AM
>
> "Raj Medhekar" <cosmicsand27 at yahoo.com>
> wrote
>
> > I am looking to build a program that gets a message
> from the user and then prints it backward. I 've been at it
> for hours now but I can't seem to figure it out.
>
> So tell us what you re thinking? How would you solve it
> manually?
>
> > I've been having trouble trying to index the message
> so I can print it out backwards.
>
> You can index the characters of a string in Python exactly
> as you do a list.
>
> > I would've posted my code but I really haven't gotten
> past the 'raw_input("Enter a message: ")' command
> line.
>
> Its always better to try something even if its wrong, it
> lets us see where your thinking is going adrift. Or at least
> describe what you'd like to do conceptually.
>
> Alan G.
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list