anonymous
  • anonymous
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.
MIT 6.00 Intro Computer Science (OCW)
jamiebookeater
  • jamiebookeater
See more answers at brainly.com
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
\t means tab
anonymous
  • anonymous
you should get two numbers number1 number2 number1 number2 and etc. like that
maitre_kaio
  • maitre_kaio
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.

Looking for something else?

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

More answers

anonymous
  • anonymous
and what version you using? is it python3?
maitre_kaio
  • maitre_kaio
http://codepad.org/wRcZjG5a
anonymous
  • anonymous
i thought he want to print that i+1 too
anonymous
  • anonymous
I use 3.2.2
anonymous
  • anonymous
I'm aware that \t is tab, but it just doesn't work....Can I take a screen shot to show you?
anonymous
  • anonymous
/Users/student/Desktop/Screen Shot 2012-01-27 at 8.34.44 PM.png
anonymous
  • anonymous
it's not screenshot lol
anonymous
  • anonymous
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
anonymous
  • anonymous
That's the part I'm struggling with.
anonymous
  • anonymous
click print screen, go to paint, click ctrl+v, save file, attach file
anonymous
  • anonymous
you didn't answer about your python version either
anonymous
  • anonymous
oh, sorry, it's 3.2.2
anonymous
  • anonymous
Python 3.2.2 it says
anonymous
  • anonymous
so it's a bit different, this course uses second version
anonymous
  • anonymous
0.0 oh...if it were just 3.2 would it work? Is there a way to get around this?
anonymous
  • anonymous
>>> print Multiples(1) SyntaxError: invalid syntax you get error because you don't have such function called Multiples
anonymous
  • anonymous
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.
anonymous
  • anonymous
print (n*i, '\t'), probably means that it print n*i makes tab and goes to new line
anonymous
  • anonymous
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.
anonymous
  • anonymous
well as i said after print(blablababla) it always goes to new line
anonymous
  • anonymous
what should I use instead?
anonymous
  • anonymous
Yes, maitre_kaio, that's what I'm trying to get to, didn't mean to ignore you:( sorry
anonymous
  • anonymous
im not sure, you should find it in book lol
anonymous
  • anonymous
ok, thnx!
anonymous
  • anonymous
maybe: print(n * i, end = '\t') http://docs.python.org/py3k/library/functions.html#print
anonymous
  • anonymous
hmmm, maybe print(n * i, *, end = '\t') there is that funny asterisk in the docs
anonymous
  • anonymous
I'll try that out! thnx!
anonymous
  • anonymous
YOU are AMAZING! it worked ! thanks you so much! I am your fan :)
anonymous
  • anonymous
which one worked? with or without the asterisk?

Looking for something else?

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