A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

Hello, I'm having some trouble with this encapsulation. The textbook "How to Think Like a Computer Scientist" tells me to input this in: def printMultiples(n): i=1 while i <= 6: print n*i, ’\t’, i=i+1 print() It says that when this is put in, if n=3, it should look like this. 3 6 9 12 15 18 However, I do not seem to be able to get the numbers to go side ways. They are always printed vertically: 3 6 9 12 15 18 What should I do? Thank you.

  • This Question is Closed
  1. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    \t means tab

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you should get two numbers number1 number2 number1 number2 and etc. like that

  3. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It would be easier to help if you had provided code in a pastebin, and the whole code. Obviously, the code that you posted is not the code you ran, because it has errors.

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    and what version you using? is it python3?

  5. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://codepad.org/wRcZjG5a

  6. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i thought he want to print that i+1 too

  7. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I use 3.2.2

  8. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm aware that \t is tab, but it just doesn't work....Can I take a screen shot to show you?

  9. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    /Users/student/Desktop/Screen Shot 2012-01-27 at 8.34.44 PM.png

  10. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    it's not screenshot lol

  11. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ugh...it doesn't go on properly >>> def printMultiples(n): i=1 while i<=6: print (n*i, '\t'), i=i+1 print() >>> print Multiples(1) SyntaxError: invalid syntax >>> printMultiples(1) 1 2 3 4 5 6 >>> def pMultiples(n): i=1 while i<=6: printMultiples(i) i=i+1 >>> pMultiples(1) 1 2 3 4 5 6 2 4 6 8 10 12 3 6 9 12 15 18 4 8 12 16 20 24 5 10 15 20 25 30 6 12 18 24 30 36

  12. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    That's the part I'm struggling with.

  13. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    click print screen, go to paint, click ctrl+v, save file, attach file

  14. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you didn't answer about your python version either

  15. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    oh, sorry, it's 3.2.2

  16. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Python 3.2.2 it says

  17. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    so it's a bit different, this course uses second version

  18. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    0.0 oh...if it were just 3.2 would it work? Is there a way to get around this?

  19. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    >>> print Multiples(1) SyntaxError: invalid syntax you get error because you don't have such function called Multiples

  20. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah...I figured that part out....I just don't get why the printMultiples(1) after that doesn't give a horizontal listing of the elements.

  21. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    print (n*i, '\t'), probably means that it print n*i makes tab and goes to new line

  22. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    mhmm, the text mentioned something previously about how print makes it go to the next line...and because its looped, it keeps changing the line every time.

  23. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    well as i said after print(blablababla) it always goes to new line

  24. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what should I use instead?

  25. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes, maitre_kaio, that's what I'm trying to get to, didn't mean to ignore you:( sorry

  26. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    im not sure, you should find it in book lol

  27. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ok, thnx!

  28. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    maybe: print(n * i, end = '\t') http://docs.python.org/py3k/library/functions.html#print

  29. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    hmmm, maybe print(n * i, *, end = '\t') there is that funny asterisk in the docs

  30. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'll try that out! thnx!

  31. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    YOU are AMAZING! it worked ! thanks you so much! I am your fan :)

  32. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    which one worked? with or without the asterisk?

  33. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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.