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