A community for students.
Here's the question you clicked on:
 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.
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

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0you should get two numbers number1 number2 number1 number2 and etc. like that

maitre_kaio
 4 years ago
Best ResponseYou've already chosen the best response.0It 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.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0and what version you using? is it python3?

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0i thought he want to print that i+1 too

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0I'm aware that \t is tab, but it just doesn't work....Can I take a screen shot to show you?

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0/Users/student/Desktop/Screen Shot 20120127 at 8.34.44 PM.png

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0it's not screenshot lol

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0ugh...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
 4 years ago
Best ResponseYou've already chosen the best response.0That's the part I'm struggling with.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0click print screen, go to paint, click ctrl+v, save file, attach file

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0you didn't answer about your python version either

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0oh, sorry, it's 3.2.2

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0so it's a bit different, this course uses second version

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.00.0 oh...if it were just 3.2 would it work? Is there a way to get around this?

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0>>> print Multiples(1) SyntaxError: invalid syntax you get error because you don't have such function called Multiples

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0yeah...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
 4 years ago
Best ResponseYou've already chosen the best response.0print (n*i, '\t'), probably means that it print n*i makes tab and goes to new line

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0mhmm, 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
 4 years ago
Best ResponseYou've already chosen the best response.0well as i said after print(blablababla) it always goes to new line

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0what should I use instead?

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Yes, maitre_kaio, that's what I'm trying to get to, didn't mean to ignore you:( sorry

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0im not sure, you should find it in book lol

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0maybe: print(n * i, end = '\t') http://docs.python.org/py3k/library/functions.html#print

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0hmmm, maybe print(n * i, *, end = '\t') there is that funny asterisk in the docs

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0I'll try that out! thnx!

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0YOU are AMAZING! it worked ! thanks you so much! I am your fan :)

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0which one worked? with or without the asterisk?
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.