Check yourself


#1

Tried the below, but it doesn't work. Regardless of what I type, the output always comes back as "empty". So even if there is a word in the console, it will come out as the "else" function....but the lesson says I did it right, even though it's not doing what I think I'm asking?

print 'Welcome to the Pig Latin Translator!'

raw_input ("Enter a word:")

original = raw_input
empty_string = ""

if len(empty_string) > 0:
print original

else:
print "empty"


PygLatin Check Youself
#2

you should prompt the user for input using raw_input, then store the result of this prompt into original, this should be accomplished in a single line of code.

what do you need empty_string for? Once you fixed your raw_input, you can use original in the if condition


#3

If I remove the empty string line of code (which was use as an example in the lesson), and type the below code, then it says there is something with the if code.

print 'Welcome to the Pig Latin Translator!'
raw_input ("Enter a word:")

original = raw_input

if len(original) > 0:
print original

else:
print "empty"


#4

that was 50% of my answer, here is the other 50%:

here:

original = raw_input

you call raw_input for the second time (without parentheses), storing a function object in original, yes, that will cause errors in if condition.

why do you need raw_input twice? The user only needs to enter one word

raw_input is a built in function, calling functions requires parentheses (unless you want the function object, but i can't imagine why)


#5

Ahhh I see what you're trying to say now. I thought you needed to separately assign the "original" value to raw input after having written the raw input code. The lesson doesn't really explain that this needs to be done, and I have seen others with the same issue, but they also include the "empty_string" command too.

Anyway, thanks! It works now.


#6

no, original is just a variable in which we store the result of calling raw_input()

so instead of storing a string in original directly:

original = "translate"

we ask the user to store a word of there choice by using raw_input (raw_input is just a function which allows us to prompt the user)


#7

word=raw_input("")
for x in range(1,len(word)):
print word[x],
print word[0]+' a y'

That's the code what I have thought but still I get spacing in between the letters in the output the interpreter gives.
Otherwise according to me everything else goes right.


#8

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