why is this code not printing the last word http://dpaste.com/780746/ it only prints john eats
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
add a space at the last of the string, like: 'john eats bread '.
It's because only when c == ' ', than the word would be printed.
you're only printing out the complete word if a space(' ') is detected. You don't have space at the end of string. If you try with 'John eats bread ', you will get to know the problem.
oh! I didn't realise Jack said the same thing. So stupid of me. Sorry!
Not the answer you are looking for? Search for more explanations.
this code print "john eats bread", your code is good, you can comment print word and word=' ' write in only line.
>>>for c in 'john eats bread':
if c!=' ':
word = word + c
word = ' '
for c in 'john eats bread ' -->you need a space
for c in 'john eats bread_'
in the following code http://dpaste.com/781646/ the the last word which is bread is translated and yet we don't have a space at the end of the sentence
Bread is translated because of the function call translateWord() lin line 22. It's not translated in Line 19-20.
All the other words are translated when they hit a space character in line 19-20. But since bread doesn't have a space char after it, it never goes into the else construct and just goes to return. But the variable word holds "bread". The return statement calls translateWord with word=bread, concatenates and returns. That's how bread is translated.