Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9046 > unrolled thread
| Started by | linda <postslot@gmail.com> |
|---|---|
| First post | 2011-07-07 11:18 -0700 |
| Last post | 2011-07-07 19:54 +0100 |
| Articles | 9 — 4 participants |
Back to article view | Back to comp.lang.python
i get different answers based on run platform linda <postslot@gmail.com> - 2011-07-07 11:18 -0700
Re: i get different answers based on run platform John Gordon <gordon@panix.com> - 2011-07-07 18:37 +0000
Re: i get different answers based on run platform Ethan Furman <ethan@stoneleaf.us> - 2011-07-07 12:11 -0700
Re: i get different answers based on run platform MRAB <python@mrabarnett.plus.com> - 2011-07-07 19:59 +0100
Re: i get different answers based on run platform linda <postslot@gmail.com> - 2011-07-07 14:09 -0700
Re: i get different answers based on run platform Ethan Furman <ethan@stoneleaf.us> - 2011-07-07 14:42 -0700
Re: i get different answers based on run platform linda <postslot@gmail.com> - 2011-07-07 14:37 -0700
Re: i get different answers based on run platform Ethan Furman <ethan@stoneleaf.us> - 2011-07-07 11:58 -0700
Re: i get different answers based on run platform MRAB <python@mrabarnett.plus.com> - 2011-07-07 19:54 +0100
| From | linda <postslot@gmail.com> |
|---|---|
| Date | 2011-07-07 11:18 -0700 |
| Subject | i get different answers based on run platform |
| Message-ID | <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> |
I have this simple palindrome program that yields different results
depending on whether I run it from Windows or from IDLE. The answer
is correct off IDLE, but why is this the case? Here's the code:
def reverse(text):
return text[::-1]
def is_palindrome(text):
return text==reverse(text)
while True:
something=input('enter text:')
print(something)
print(something[::-1])
if (is_palindrome(something)):
print("yes, it is a palindrome")
break
else:
print("no, it is not a palindrome")
continue
print ('done')
Thanks for your help.
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2011-07-07 18:37 +0000 |
| Message-ID | <iv4ue2$ij0$1@reader1.panix.com> |
| In reply to | #9046 |
In <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> linda <postslot@gmail.com> writes:
> I have this simple palindrome program that yields different results
> depending on whether I run it from Windows or from IDLE. The answer
> is correct off IDLE, but why is this the case? Here's the code:
Your code contains debugging statements that print the value of the normal
string and the reversed string. What do those statements print when you
run your program under Windows? That should go a long way towards telling
you what the problem is.
(Perhaps Windows leaves a linefeed character hanging at the end of the
input line, which upsets the palindromic balance?)
By the way, I could not make your program work as you provided it; I had
to replace input() with raw_input(). Does it really work for you this way?
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2011-07-07 12:11 -0700 |
| Message-ID | <mailman.761.1310065041.1164.python-list@python.org> |
| In reply to | #9050 |
John Gordon wrote: > By the way, I could not make your program work as you provided it; I had > to replace input() with raw_input(). Does it really work for you this way? input() is the 3.x name for raw_input() ~Ethan~
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2011-07-07 19:59 +0100 |
| Message-ID | <mailman.762.1310065208.1164.python-list@python.org> |
| In reply to | #9050 |
On 07/07/2011 19:37, John Gordon wrote: > In<842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> linda<postslot@gmail.com> writes: > >> I have this simple palindrome program that yields different results >> depending on whether I run it from Windows or from IDLE. The answer >> is correct off IDLE, but why is this the case? Here's the code: > > Your code contains debugging statements that print the value of the normal > string and the reversed string. What do those statements print when you > run your program under Windows? That should go a long way towards telling > you what the problem is. > > (Perhaps Windows leaves a linefeed character hanging at the end of the > input line, which upsets the palindromic balance?) > > By the way, I could not make your program work as you provided it; I had > to replace input() with raw_input(). Does it really work for you this way? > It's Python 3. Python 2's raw_input() has been renamed input() in Python 3 and Python 2's input() was never in Python 3 because it uses eval on the string, which usually undesirable.
[toc] | [prev] | [next] | [standalone]
| From | linda <postslot@gmail.com> |
|---|---|
| Date | 2011-07-07 14:09 -0700 |
| Message-ID | <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> |
| In reply to | #9054 |
I tried something = input('enter text:').rstrip('\n') as suggested but
the problem persists. BTW, the intermediate print commands agree and
so are not an issue. The disagreement is in IDLE correctly
identifying palindromes and Windows not. I do suspect it may be a
trailing '\r' issue. Is there an easy fix or shall I wait for the new
Python versions to be released? Thanks for helping.
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2011-07-07 14:42 -0700 |
| Message-ID | <mailman.764.1310074094.1164.python-list@python.org> |
| In reply to | #9057 |
linda wrote:
> I tried something = input('enter text:').rstrip('\n') as suggested but
> the problem persists. BTW, the intermediate print commands agree and
> so are not an issue. The disagreement is in IDLE correctly
> identifying palindromes and Windows not. I do suspect it may be a
> trailing '\r' issue. Is there an easy fix or shall I wait for the new
> Python versions to be released? Thanks for helping.
My apologies -- change the '\n' to '\r' and that will hopefully do the
trick.
~Ethan~
[toc] | [prev] | [next] | [standalone]
| From | linda <postslot@gmail.com> |
|---|---|
| Date | 2011-07-07 14:37 -0700 |
| Message-ID | <e6e368cc-98ad-4095-8d64-35014487b377@y30g2000yqb.googlegroups.com> |
| In reply to | #9058 |
On Jul 7, 2:42 pm, Ethan Furman <et...@stoneleaf.us> wrote:
> linda wrote:
> > I tried something = input('enter text:').rstrip('\n') as suggested but
> > the problem persists. BTW, the intermediate print commands agree and
> > so are not an issue. The disagreement is in IDLE correctly
> > identifying palindromes and Windows not. I do suspect it may be a
> > trailing '\r' issue. Is there an easy fix or shall I wait for the new
> > Python versions to be released? Thanks for helping.
>
> My apologies -- change the '\n' to '\r' and that will hopefully do the
> trick.
>
> ~Ethan~
Thanks Ethan--that did work :)
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2011-07-07 11:58 -0700 |
| Message-ID | <mailman.759.1310064169.1164.python-list@python.org> |
| In reply to | #9046 |
linda wrote:
> I have this simple palindrome program that yields different results
> depending on whether I run it from Windows or from IDLE. The answer
> is correct off IDLE, but why is this the case? Here's the code:
>
> def reverse(text):
> return text[::-1]
> def is_palindrome(text):
> return text==reverse(text)
> while True:
> something=input('enter text:')
try changing this to:
something = input('enter text:').rstrip('\n')
> print(something)
> print(something[::-1])
> if (is_palindrome(something)):
> print("yes, it is a palindrome")
> break
> else:
> print("no, it is not a palindrome")
> continue
> print ('done')
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2011-07-07 19:54 +0100 |
| Message-ID | <mailman.760.1310064891.1164.python-list@python.org> |
| In reply to | #9046 |
On 07/07/2011 19:18, linda wrote:
> I have this simple palindrome program that yields different results
> depending on whether I run it from Windows or from IDLE. The answer
> is correct off IDLE, but why is this the case? Here's the code:
>
> def reverse(text):
> return text[::-1]
> def is_palindrome(text):
> return text==reverse(text)
> while True:
> something=input('enter text:')
> print(something)
> print(something[::-1])
> if (is_palindrome(something)):
> print("yes, it is a palindrome")
> break
> else:
> print("no, it is not a palindrome")
> continue
> print ('done')
>
> Thanks for your help.
>
Try printing ascii(something) too.
There's a known bug in Python 3.2 where it leaves a training '\r', if
that's what you're using (http://bugs.python.org/issue12435), fixed in
Python 3.2.1.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web