473,287 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Re: A quick question

On Wed, 28 May 2008 10:25:01 -0000
"James" <co******@msn.comwrote:
Hey everyone,

I just started using python and cant figure this out, I'm trying to
make a program where someone types in a word and the program gives it
back backwards. For example if the person puts in "cat" I want the
program to give it back as "tac" and what it does is prints out 3,2,1.
How can I get these integers to print as letters? This is what I have,

word = raw_input("Type a word:")
start = len(word)

for letter in range(start, 0, -1):
print letter
Ignore my previous message. Too early. Here is your script:

word = raw_input("Type a word:")
for i in range(len(word), 0, -1):
print word[i]

Sorry about that.

--
D'Arcy J.M. Cain <da***@druid.net | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
Jun 27 '08 #1
1 920
D'Arcy J.M. Cain a écrit :
On Wed, 28 May 2008 10:25:01 -0000
"James" <co******@msn.comwrote:
>Hey everyone,

I just started using python and cant figure this out, I'm trying to
make a program where someone types in a word and the program gives it
back backwards. For example if the person puts in "cat" I want the
program to give it back as "tac" and what it does is prints out 3,2,1.
How can I get these integers to print as letters? This is what I have,

word = raw_input("Type a word:")
start = len(word)

for letter in range(start, 0, -1):
print letter

Ignore my previous message. Too early. Here is your script:

word = raw_input("Type a word:")
for i in range(len(word), 0, -1):
print word[i]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range

sequence indices are zero-based, so you want to start at len(word) -1.
And the range upper limit (second argument) is not included. So you want
to pass -1 here.
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.