PygLatin not working


#1

This is my code.

print 'Welcome to the Pig Latin Translator!'

raw_input('Enter a word:')
original = raw_input

if len(original) > 0 and original.isalpha() == True:
print 'original'
else:
print 'empty'

It returns this:

Welcome to the Pig Latin Translator!
Enter a word: 23
Traceback (most recent call last):
File "python", line 6, in
TypeError: object of type 'builtin_function_or_method' has no len()

When I eliminate the == True part:

print 'Welcome to the Pig Latin Translator!'

raw_input('Enter a word:')
original = raw_input

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

It gives me this:

Welcome to the Pig Latin Translator!
Enter a word: 23
Traceback (most recent call last):
File "python", line 6, in
TypeError: object of type 'builtin_function_or_method' has no len()

I am stumped. Have looked over this forum and multiple others to no avail.


#2

That is not how you use raw_input and input in 3.4.

You use it like,

ask = raw_input("Raw_input returns a value if you do not capture it, it goes bye-bye.")

Easy enough?

Also, python automagically evaluates an if statement to True if there is no comparitor.

Example:

a = True
if a:
    print(True)

See, so you can simplify

to

if original and original.isalpha():

Also if there is any data in a variable it is equal to True, if empty it's False.

Any questions?


#3

print 'Welcome to the Pig Latin Translator!'

raw_input('Enter a word:')
original = raw_input

if original and original.isalpha():
print 'original'
else:
print 'empty'

Result:

Welcome to the Pig Latin Translator!
Enter a word: 23
Traceback (most recent call last):
File "python", line 6, in
AttributeError: 'builtin_function_or_method' object has no attribute 'isalpha'

I think I'm missing something.


#4

You have to pass the function a string.

a_function('string')