[Tutor] Help Passing Variables
Daniel Gulko
dangulko at hotmail.com
Thu Oct 18 09:08:08 CEST 2012
Hi Python Tutor, I have a write a simple function named "SwapCaseAndCenter(a_string, width). 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:
a_string=raw_input("give me a word: (enter to quit): ")
if a_string:
print a_string.center(60).swapcase()
elif not a_string:
print "you did not provide a word. goodbye"
break SwapCaseAndCenter(a_string)
Thanks, Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121018/dbf6a05b/attachment-0001.html>
More information about the Tutor
mailing list