Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82518
| References | <3abc022a-2916-4bfb-b722-20037a646045@googlegroups.com> |
|---|---|
| Date | 2014-12-14 18:26 +0100 |
| Subject | Re: How to use the .isalpha() function correctly |
| From | Chris Warrick <kwpolska@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16952.1418578022.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web