Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82514 > unrolled thread

How to use the .isalpha() function correctly

Started byLuke Tomaneng <luketomaneng@gmail.com>
First post2014-12-14 09:16 -0800
Last post2014-12-14 09:29 -0800
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How to use the .isalpha() function correctly Luke Tomaneng <luketomaneng@gmail.com> - 2014-12-14 09:16 -0800
    Re: How to use the .isalpha() function correctly Chris Warrick <kwpolska@gmail.com> - 2014-12-14 18:26 +0100
      Re: How to use the .isalpha() function correctly Luke Tomaneng <luketomaneng@gmail.com> - 2014-12-14 09:29 -0800

#82514 — How to use the .isalpha() function correctly

FromLuke Tomaneng <luketomaneng@gmail.com>
Date2014-12-14 09:16 -0800
SubjectHow to use the .isalpha() function correctly
Message-ID<3abc022a-2916-4bfb-b722-20037a646045@googlegroups.com>
Here a very small program that I wrote for Codecademy. When I finished, Codecademy acted like it was correct, but testing of this code revealed otherwise.
--------------------------------------------------
print 'Welcome to the Pig Latin Translator!'

# Start coding here!
raw_input("Enter a word:")
original = str(raw_input)
if len(original) > 0 and original.isalpha():
    print original
else:
    print "empty"
--------------------------------------------------
No matter what I type in, the result is "empty." What do I need to do in order for it to accept words?

[toc] | [next] | [standalone]


#82518

FromChris Warrick <kwpolska@gmail.com>
Date2014-12-14 18:26 +0100
Message-ID<mailman.16952.1418578022.18130.python-list@python.org>
In reply to#82514
On Sun, Dec 14, 2014 at 6:16 PM, Luke Tomaneng <luketomaneng@gmail.com> wrote:
> Here a very small program that I wrote for Codecademy. When I finished, Codecademy acted like it was correct, but testing of this code revealed otherwise.
> --------------------------------------------------
> print 'Welcome to the Pig Latin Translator!'
>
> # Start coding here!
> raw_input("Enter a word:")
> original = str(raw_input)
> if len(original) > 0 and original.isalpha():
>     print original
> else:
>     print "empty"
> --------------------------------------------------
> No matter what I type in, the result is "empty." What do I need to do in order for it to accept words?
> --
> https://mail.python.org/mailman/listinfo/python-list

That’s not where the error is, actually.  You are:

1. taking input with "Enter a word: " and NOT SAVING IT
2. setting original to a string representation of the function
`raw_input`, which is something like

>>> str(raw_input)
'<built-in function raw_input>'

The correct way to do this is:

original = raw_input("Enter a word: ")

as raw_input already outputs a string.

-- 
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

[toc] | [prev] | [next] | [standalone]


#82520

FromLuke Tomaneng <luketomaneng@gmail.com>
Date2014-12-14 09:29 -0800
Message-ID<d1f123a4-fdd3-4933-9438-ae391802c6ee@googlegroups.com>
In reply to#82518
On Sunday, December 14, 2014 9:27:14 AM UTC-8, Chris Warrick wrote:
> On Sun, Dec 14, 2014 at 6:16 PM, Luke Tomaneng <luketomaneng@gmail.com> wrote:
> > Here a very small program that I wrote for Codecademy. When I finished, Codecademy acted like it was correct, but testing of this code revealed otherwise.
> > --------------------------------------------------
> > print 'Welcome to the Pig Latin Translator!'
> >
> > # Start coding here!
> > raw_input("Enter a word:")
> > original = str(raw_input)
> > if len(original) > 0 and original.isalpha():
> >     print original
> > else:
> >     print "empty"
> > --------------------------------------------------
> > No matter what I type in, the result is "empty." What do I need to do in order for it to accept words?
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> That's not where the error is, actually.  You are:
> 
> 1. taking input with "Enter a word: " and NOT SAVING IT
> 2. setting original to a string representation of the function
> `raw_input`, which is something like
> 
> >>> str(raw_input)
> '<built-in function raw_input>'
> 
> The correct way to do this is:
> 
> original = raw_input("Enter a word: ")
> 
> as raw_input already outputs a string.
> 
> -- 
> Chris Warrick <https://chriswarrick.com/>
> PGP: 5EAAEA16

Thanks very much. I'm not sure how I missed that, since I've used the exact same method you mentioned before. You've been very helpful.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web