Check Yourself!


#1


https://www.codecademy.com/en/courses/python-beginner-2W5v7/0/4?curriculum_id=4f89dab3d788890003000096

Hi, my code works and I'm able to move to the next exercise, but there's something I don't think should be happening.

If I write the code, click "Save & Submit Code" and do not write anything I get:

Welcome to the Pig Latin Translator!
Enter a word:

empty
None

The "empty" appears because I didn't write anything, right?
But if I do write something, I get:

Welcome to the Pig Latin Translator!
Enter a word: word

empty
None

Exactly the same thing, except I wrote something and the "empty" still appears below.
Is it supposed to be like this? Am I doing something wrong?


print 'Welcome to the Pig Latin Translator!'

# Start coding here!
raw_input("Enter a word:")
original = raw_input()
if len(original) > 0:
    print original
else:
    print "empty"


#2

If you are on the check yourself lesson you should also check if it only contains only letters using the isalpha() python method.

And remove the first raw_input()


#3

why do you have raw_input twice? You only have to prompt the user for a single word


#4

I don't know why you both told me to "remove the first first raw_input()", the exercise started with it, I only had to add the if statements.

Also I haven't seen anything teaching me about this isalpha() method yet. This exercise doesn't mention it so I don't know why it should be a requirement.
Still, my question wasn't answered.

I've edited the topic to add a link to the exercise.


#5

For one, an input should be stored in a variable this one is not,

second of all in the check yourself lesson they do explain and tell you to include the .isalpha() method, read carefully :slight_smile:


#6

The question is asking that ensure the user actually typed something. So the answer would be like? Not sure if I explain this clear enough.

original = raw_input("What's your name") #First they ask the user type something.
print 'Welcome to the Pig Latin Translator!' #Welcome the user.

if len(original) > 0: #len(original) syntax from words to numbers, example Uvewewe 7 letters and the fact is 7 > 0 = True.
    print original #Because it is TRUE, so python didn't skip the first print.
    
else: #But when if len(original) > 8 = False.
    print "empty" #Finally Python print "empty".

Hope this help. :grinning:


#8

@boardrunner65128

you did it perfectly for the lesson, you just forgot to add in the variable.

empty_string = ""

Just define it under the comment!


#9

you can show how do it please y have this code

print "Bienvenido al traductor de espanol a Pig Latin."
print "ingrese la palabra a traducir"
original = raw_input("ingresa una palabra:")
if len(original)>0:
print(original)
else:
print("vacío")

and produce this error
File "python", line 4
if len(original)>0:
^
IndentationError: unexpected indent

iḿ question for this but don't have an answer that helpme
and i'm searching but only find codes some that my

(sorry my english is not good... i'm speak spannish)


#10

2 posts were split to a new topic: Check yourself


#11

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