On 10/18/2012 03:08 AM, Daniel Gulko wrote:
>
>
>
> Hi Python Tutor, I have a write a simple function named 
> "SwapCaseAndCenter(a_string, width). 

So why did you define it with only one formal parameter?

> The idea is to use the function swapcase and center so that when the 
> userenters a string it centers it and swaps the case (e.g. upper to lower and 
> vice versa).  The function calls for passing in two variables "a_string, 
> width" but I am still confused on this concept.  In my code below I seem to 
> be able to pass in the variable "a_string" and found out how to use the 
> "center along with swapcase" functions. I am still unsure howto pass in the 
> variable "width". In my code I have hard coded the centering but I am not 
> sure if instead I use the variable width to determine the centering. Any 
> suggestions, help or examples of how to do this is appreciated.  
> def SwapCaseAndCenter(a_string):    while True: 

As you can see, your email program thoroughly messed up this source
code.  Please send your messages in text form, as html frequently gets
trashed as it goes through various gateways.  This is a text-mailing list.

>         a_string=raw_input("give me a word: (enter to quit): ")     
>  

Why do you ask the user for the input, when it was already supplied as a
parameter?  it's best practice to separate input from calculation, and
your teacher had done that in his/her specification.

>        if a_string:
>             print a_string.center(60).swapcase()
>         elif not a_string:
>             print "you did not provide a word. goodbye"
Presumably you should be returning the centered/swapped string.

No idea where the following break is supposed to happen.  But once you
eliminate the raw_input, you'll be eliminating the while True and the break.

>         break SwapCaseAndCenter(a_string)
> Thanks, Dan                                     
-- 
DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to