Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

mwas Group Title

why is this code not printing the last word http://dpaste.com/780746/ it only prints john eats

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. Jack_Li Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  2. jaskiratsingh Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  3. jaskiratsingh Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    oh! I didn't realise Jack said the same thing. So stupid of me. Sorry!

    • 2 years ago
  4. lopus Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    this code print "john eats bread", your code is good, you can comment print word and word=' ' write in only line. >>>word=' ' >>>for c in 'john eats bread': print c if c!=' ': word = word + c else: #print word word = ' '

    • 2 years ago
  5. lopus Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    for c in 'john eats bread ' -->you need a space for c in 'john eats bread_'

    • 2 years ago
  6. mwas Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • 2 years ago
  7. jaskiratsingh Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  8. mwas Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i hav got it thanks

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.