8/11 Word Up


#1

Can someone tell me why this code is wrong? Is there an actual reason it wouldn’t work or is it just because the lesson wants me to do it another way?

pyg = ‘ay’

original = raw_input(‘Enter a word:’).lower()

if len(original) > 0 and original.isalpha():
first = original[0]
print original
else:
print ‘empty’


#2

I think in this case, if you’re getting a red cross for the exercise it’s because the instruction specifically asks for two things and your code does neither.

It doesn’t mean that your code is wrong, or that it won’t run. I think it’s just that Codecademy’s editor is expecting you to do things a particular way this time, and won’t let you pass if it’s not precisely what it wanted. :slight_smile:

It can be a bit fussy at times.


#3

Yeah, I know that’s why I got the red cross for the exercise, I was just wondering if there was a reason down the line for the lesson to not like my code or if it was just because the exercise arbitrarily picked a way to do it and I had done it a different, but equally right, way.


#4

It varies.

In some cases, like this one, Codecademy seems to just look at your code and check whether you’ve declared what they asked you to declare. In this case, they seemed to want you to declare a specific variable, and when their regex evaluation didn’t detect it they threw you an error. (I’m not privy to the exact methods Codecademy uses to validate exercise input; simply guessing based on what I’ve encountered.)

Other times, what’ll happen is they’ll ask you to define a function for example, then validate your code by just calling the function with a range of arguments and checking that what comes out is right for each argument.

It can get a bit frustrating, having written perfectly viable code only to have Codecademy come back with an arbitrary “Sorry, that’s wrong” for what seems like no good reason, but it’s one of the unavoidable drawbacks of having an online learning platform automatically and instantly “grade” your code.

Eventually, you get used to it and just do what they’ve asked for in the exercise, even when it seems a bit repetitive or excessively… basic. :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.