Python - Pyglatin - 4. Check yourself


UPDATE


If you are having trouble with exercise 4 then this is the thread that explains it all. If you read towards the end of the conversation you will see that @albionsrefuge confirms that this is a bug in the course. Unfortunately due to response times it seems it is very unlikely that it will be fixed. Please read to see the correct syntax to the exercise but I encourage you to do additional research to understand the context because I overlooked this myself and now that I have gone back over my notes it makes perfect sense.

Original Post

Please keep in mind that when you start this section that it starts with the following code:

print 'Welcome to the Pig Latin Translator!'

# Start coding here!
raw_input("Enter a word:")
original = raw_input

Yesterday I was working through the Python module and started the Pig Latin section. When I got to section 4. Check yourself! I ran into a problem. The code appears to be correct but it will return the following error:

Traceback (most recent call last):
File “python”, line 9, in
TypeError: object of type ‘builtin_function_or_method’ has no len()

I have done some research to try and figure out why this is a problem. I have seen solutions that suggest to use the .isalpha() function but I think this is suppose to be for the next section 5. check yourself… some more. Len() according to the Python site states that this only checks to see how many in what ever variable you call so this should come back as true statement. I have seen suggestions made saying that an additional set of parentheses should be added to the function raw_input when saving it to the variable in line 6 (see code below) so that it appears as “original = raw_input()” but all this does when I run the code is prompt me for another input.

# Welcome Message for user
print 'Welcome to the Pig Latin Translator!'

# asking user for input
raw_input("Enter a word:")
original = raw_input

# Time to verify that user entered valid characters
if len(original) > 0:
    print original
else:
    print "empty"

The next day I came back to try this again and found that I was automatically in the next section 5. Check yourself… some more. I returned to the previous section as soon as I realized that I was in the next section without resolving the problem I was having the previous day. After some more research I began to suspect that this was a bug and my code was not at fault. Eventually I tried the following code as well as found a reference that confirmed my suspicion that this is a bug in the module…

# Welcome Message for user
print 'Welcome to the Pig Latin Translator!'

# asking user for input
original = raw_input("Enter a word:")

# Time to verify that user entered valid characters
if len(original) > 0:
    print original
else:
    print "empty"

My References:

CodeCademy Bug confirmation
Python Site
Work around code

This link is broken, do you think you could re-link it?

The link is fixed and you should be able to see the original post from 2013.

It looks like the SCT (submission correctness test) for exercise 3 is too lazy. It should never have accepted:

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

We do not want to set original to the raw_input function itself. We instead want to set it to the value returned from the raw_input function, which we can do as you have suggested with:

original = raw_input("Enter a word:")

@albionsrefuge are you saying that the second piece of code that I placed in my OP is the correct format?

# Welcome Message for user
print 'Welcome to the Pig Latin Translator!'

# asking user for input
original = raw_input("Enter a word:")

# Time to verify that user entered valid characters
if len(original) > 0:
    print original
else:
    print "empty"
My References:

Yes, it is the correct way to ask the user a question and store the result in a variable.

@albionsrefuge what can we do to make sure this is corrected then?

I’d like to say that there is a timely process in place for fixing these sorts of things, but there isn’t. Historically bugs like this have been reported and if someone has time to fix them they might get fixed but generally there is no engineering time set aside to focus on bug fixing – at least not in these older courses. Bug fix response time is better in the newer courses.

For now, posting it here, as you have done, is the best thing to do.

Can we sticky the thread so people easily find it?