Check Yourself Some More .isalpha


#1

When I go on check yourself some more and I run my code it says that .isalpha isn't proper syntax and it is called a code error. I was wondering what I was doing wrong, thanks.


#2

Hi @qaz1qaz ,

We cannot figure out what you did wrong without our seeing your code. Please post it.

Here's an example of how the len function and the isalpha method can be used, assuming that the variable, original, refers to a string:

if len(original) > 0 and original.isalpha():

Note, in the above, that because isalpha is a method, dot syntax is used, which differs from the manner in which the len function is used.


#3

print 'Welcome to the Pig Latin Translator!'

start coding here!

raw_input("Hello")
original=raw_input
if original>0 and raw_input.isalpha():
print original
else:
print "empty"

That's my code above. Thanks for your help!


#4

@geomaticmashups ^ is my code


#5

@qaz1qaz

You cannot call the method isalpha() on raw_input, isalpha is strictly a method of a string.

That is not valid code, you have to pass the original variable to it instead.

if original.isalpha():
    print(original)

That should clear up your issue.


#6

It's all mangled though, perhaps you should take the time to make sure that it's intact


#8

Sorry again but I am still not sure what to do. I have previously tried a lot of different variations in the coding and just retried it with the original variable as I have before and it still is not working. When I do the code:
raw_input("Hello")
original=raw_input
if original>0 and original.isalpha():
print original
else:
print "empty"
The error message is "'builtin_function_or_method' object has no attribute 'isalpha'
Thanks again for the help, I've been working on this one part for almost two weeks and spent about 5 hours trying to figure it out. The help means a lot :smile:


#9

Well in the beginning of your code just put original=raw_input("Hello").
Remove the "original=raw_input" since you are basically repeating yourself.
Then for your if statement you are missing your () wrapped around your original sign. SO it should read" if (original)>0 and original.isalpha():" the rest looks good.
SO your code should look like this:

print 'Welcome to the Pig Latin Translator!'

Start coding here!

original=raw_input("Enter a word:")
if (original)>0 and original.isalpha():
print original
else:
print "empty"

I hope that helps. I replaced some of your words which you can always switch it back. It will also tell you on the right of screen to actually type in a word and press enter.


#10

Thank you so much I got past it, and I actually understand why now. Thanks!!!


#11

thanks a lot .. your code helped :smile:


#12

Okay so, when I tried this, it didn't work.. Not sure why.. My code is

print 'Welcome to the Pig Latin Translator!'
original = raw_input("Enter a Word:")
if (original) > 0 and original.isaplha():
print original
else:
print "Empty"
Saying somethings wrong in 4th line, but i'm not sure what.. Please help! Thank you!


#13

For everyone having problems with this, I admit it is a bit different from what I was expecting. In your if line, add this for the .isalpha() check.

str(original).isalpha()

.isalpha has to be applied after the string is called to the check. Hope this helps everyone who is having problems!

My full code (If you want to cross reference)


print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word:")

if str(original).isalpha()==True and len(original)>0 :
* print str(original)*
else:
* print "You have to type something"*


#14

I have tried this exact code and it still seems to not work. I believe everything is right I just cant seem to see why it isn't working


#15

print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word:")
empty_string = ""
if len(original) > 0: and original.isalsha():
print original
else:
print "empty"

put this code in the thing and it won't work. it say my code is a bit of. Plz Plz help somebody


#16

thank you very much Thomas Krys with a number 13 you hAVE helped me a lot. Thank you very much


#17

Just make sure in your if statement that the .isalpha() isn't alone. Attach it to the "Original" string.


#18

I was having trouble and it was just because I neglected to notice there was supposed to be a placeholder before .isalpha() > 0:
which is supposed to be original.isalpha() > 0:

print 'Welcome to the Pig Latin Translator!'

Start coding here!

raw_input("Case")
original = raw_input("Case")

if len(original) and original.isalpha() > 0:
print "original"
else:
print "empty"


#19

Everything for me seems to be working but when i hit return for some reason it doesnt reply with empty.
Here's what i got so far:

print 'Welcome to the Pig Latin Translator!'
original = raw_input('Python')
if str(original) > 0 and original.isalpha():
print "Original."
else:
print "empty"
original = raw_input('Python')


#20

i have this so far

print 'Welcome to the Pig Latin Translator!'

Start coding here!

original = raw_input ("Enter a word:")
if len(original) > 0: and original.isalpha():
print original
else:
print "empty"

but receive following error
File "python", line 5
if len(original) > 0: and original.isalpha():
^
SyntaxError: invalid syntax


#21

find the error. after I deleted : after 0 the code run.

if len(original) >0
and not if len(original) >0: