Difference between the result and the comments


#1



The screen on the right shows that I have run the correct program, however the comment on the edge always says that

Oops, try again. It looks like new_word contains "helloay" instead of "ellohay"!


print "welcome to the Pig latin world!"
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
    new_word = str(word) + str(first) + str(pyg)
    print "new word: " + new_word[1:len(new_word)]
else:
    print 'empty'


#2

It says that your variable contains one value instead of another. Have you tried investigating what that variable contains, since that's what it says is wrong?

You're experiencing confirmation bias. You see the value you expect and therefore assume everything is right - but the error message says exactly what is wrong.


#3

A couple of things are unexpected in the code and output.

str(word)

word is already a string.

x + y + z

Is an unexpected embellishment. Remove and print the remaining.


#4

Thanks a lot! I tried to figure out the problem. I find the only place that variable contains on value instead of another is in line 10.

I tried to change it into new_word[1:], but it does not work
And I also try to delete what mtf says that is unexpected, but some other problems shows.
I am still search in the community to find out some solutions.
It would be really nice that you could give me more suggestions.


#5

The variable needs to refer to a particular value.
That means you need to assign the correct value to that variable.
printing the variable should print out the correct value
You are currently printing the result of an expression that involves that variable, but you're printing the result of that expression, not the variable.

It's like doing this:

a = 1
b = 1

print(a + b) # prints 2

2 is printed, but if the intention is that b should refer to 2, then the code is wrong, because b refers to 1, what's printed is something else entirely and does not affect the value that b refers to


#6

Got it! Thank you very much!


#7

Thank you very much!!!


#8

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