[Tutor] textbook question

Justin Bonnell jwbonnell5 at gmail.com
Mon Feb 28 06:36:43 CET 2011


In trying to learn Python, I'm reading through How to Think Like a Computer Scientist. I'm just on the third chapter but I'm getting stuck on this question:

Fill in the body of the function definition for cat_n_times so that it will print the string, s, n times:

def cat_n_times(s, n):
    <fill in your code here>
Save this function in a script named import_test.py. Now at a unix prompt, make sure you are in the same directory where the import_test.py is located ( ls should show import_test.py). Start a Python shell and try the following:

>>> from import_test import *
>>> cat_n_times('Spam', 7)
SpamSpamSpamSpamSpamSpamSpam
If all is well, your session should work the same as this one. Experiment with other calls to cat_n_times until you feel comfortable with how it works.

I'm thinking it should be pretty easy but, again, I'm a beginner.
I copied the whole question but basically I just need some help with what the script should look like, that'd be great.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110227/473d84a1/attachment-0001.html>


More information about the Tutor mailing list