[Tutor] Just Joined!

Wayne Werner waynejwerner at gmail.com
Thu May 12 14:05:32 CEST 2011


On Thu, May 12, 2011 at 6:34 AM, Alex Smith <alexsmith24871 at yahoo.com>wrote:

> Hi All,
>

>
I just joined this list and am really new to python.
>

Hi! Welcome to the Python tutor list, and Python!


> I have an assignment to create a function with (a_string, width) which
> returns the a_string with all the lower case characters changed to upper
> case characters and vice versa and centered; was wondering if someone could
> point me in the right direction. I am not just asking for the answer but
> just need a few tips to get started.
>

That's good, because that's our policy here ;)


>  So far I do know I should use the dir(str)
>

I think you might be a little confused as to what dir actually does, or
maybe what your assignment is really asking!


> and do not quite understand what the "width" option is used for....
>

Since you said the text is supposed to be centered, I suspect it means the
final width of the string...


> >>> help(dir)
> <snip>
>
    Return an alphabetized list of names comprising (some of) the attributes
>     of the given object, and of attributes reachable from it:<snip>
>

So dir gives you the attributes of an object. In this case since you're
playing with a string you want to take a look at string objects. What
happens when you run dir(str)? What happens when you run dir('this is a
string')?


>
> def SwapcaseAndCenter(dir,??)
>

The best way to understand what an assignment is asking is usually to have
an example - and if you don't have an example, make one up!

So I suspect your teacher might want something like this: (I'm replacing
spaces with 'x' so you can see them. It's a good thing to do while you're
testing)

>>> SwapcaseAndCenter('a', 3)
'xAx'
>>> SwapcaseAndCenter('hello', 10)
'xxHELLOxxx'
>>> SwapcaseAndCenter('WeIrD', 12)
'xxxwEiRdxxxx'

I suspect if you look carefully at the output of the `dir` commands that I
mentioned above, you will find some help.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110512/007dbd61/attachment.html>


More information about the Tutor mailing list