Newb ?

C

Chad Everett

Hello all,

Have a problem here with a challenge from a book I am reading.
Any help is much appreciated.

I am trying to run a program that asks the user for a statement and then
prints it out backwards.
this is what I have.
It does not print anything out. I assume that I have something out of whack
with my high and low statements.

Thanks for you help.


print "\n\nWelcome to the Backwards Message Display."
print
message = raw_input("\nPlease Enter a Message.")

high = len(message)
low = -len(message)
print
print message[high:low]
print
print raw_input("Please Press Enter to Exit")
 
P

Paul Watson

Chad said:
Hello all,

Have a problem here with a challenge from a book I am reading.
Any help is much appreciated.

I am trying to run a program that asks the user for a statement and then
prints it out backwards.
this is what I have.
It does not print anything out. I assume that I have something out of whack
with my high and low statements.

Thanks for you help.


print "\n\nWelcome to the Backwards Message Display."
print
message = raw_input("\nPlease Enter a Message.")

high = len(message)
low = -len(message)
print
print message[high:low]
print
print raw_input("Please Press Enter to Exit")

Are you sure that this is not a class assignment? You can search the
messages here for the answer.
 
C

Chad Everett

Paul Watson said:
Chad said:
Hello all,

Have a problem here with a challenge from a book I am reading.
Any help is much appreciated.

I am trying to run a program that asks the user for a statement and then
prints it out backwards.
this is what I have.
It does not print anything out. I assume that I have something out of
whack with my high and low statements.

Thanks for you help.


print "\n\nWelcome to the Backwards Message Display."
print
message = raw_input("\nPlease Enter a Message.")

high = len(message)
low = -len(message)
print
print message[high:low]
print
print raw_input("Please Press Enter to Exit")

Are you sure that this is not a class assignment? You can search the
messages here for the answer.

No, I have been out of school way too long. I am 34 trying to learn a new
trade. I searched the group for the term backwards but I did not get any
results.
 
M

Mike Meyer

Chad Everett said:
print "\n\nWelcome to the Backwards Message Display."
print
message = raw_input("\nPlease Enter a Message.")

Since you said it wasn't a school assignment, and I'm a trusting soul,
the next line could be:

print message[::-1]

<mike
 
S

Scott David Daniels

Chad said:
Chad said:
high = len(message)
low = -len(message)
print
print message[high:low]
print
print raw_input("Please Press Enter to Exit")

Are you sure that this is not a class assignment? You can search the
messages here for the answer.


No, I have been out of school way too long. I am 34 trying to learn a new
trade. I searched the group for the term backwards but I did not get any
results.

The problem is that negative numbers mean "count from the rightmost end
of the string or list." Also, you are going high to low without any
indication that you mean to go backwards.
>>> message = raw_input("Enter a Message:")
>>> print message[: : -1]

-Scott David Daniels
(e-mail address removed)
 
C

Chad Everett

Hey guys,

Thanks for the hint.
I found that info last night but I could never get it to print more than
just the last letter.
or it would only print partially.
I was using just a single colon, the double colon did it.

Thanks
 
P

Paul Watson

Chad said:
Hey guys,

Thanks for the hint.
I found that info last night but I could never get it to print more than
just the last letter.
or it would only print partially.
I was using just a single colon, the double colon did it.

If you were using a single colon, then it would print everything except
the last character. Use the Python interactive mode for experimentation.

$ python
Python 2.4.1 (#1, Jul 19 2005, 14:16:43)
[GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = 'abc'
>>> s 'abc'
>>> s[:-1] 'ab'
>>> s[-1]
'c'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top