What is the matter with this code? (PygLatin 4/11


#1

Hi! I’m new to Codecademy, and I can’t figure out why my code is not working properly.
The first code is the Codecademy solution:
print ‘Welcome to the Pig Latin Translator!’

Start coding here!

original = raw_input(“Enter a word:”)
if len(original) > 0:
print original
else:
print “empty”

This code down here is the answer I gave:

print ‘Welcome to the Pig Latin Translator!’

Start coding here!

original = raw_input(“Enter a word:”)
if len(empty_string) > 0:
print original
else:
print “empty”

I can’t see any difference between the two. What is the matter?


#2

correct code:

if len(original) > 0:

your code:

if len(empty_string) > 0:

empty_string is an undefined variable, while in the correct code the length of original is checked, this variable contains the user input, you want to ensure the user entered at least one character


#3

Thanks a bunch! I appreciate it. :slight_smile:


#4

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