David Hutto wrote:
> #A little more complex in terms of params:
>
> def SwapCaseAndCenter(*kwargs):
>
> if upper_or_lower == "upper":
> print a_string.center(center_num).upper()
>
> if upper_or_lower == "lower":
> print a_string.center(center_num).lower()
#Apologies, this is the actual code:
def SwapCaseAndCenter(a_string, upper_or_lower = None, center_num = None):
if upper_or_lower == "upper":
print a_string.center(center_num).upper()
if upper_or_lower == "lower":
print a_string.center(center_num)
#A little more complex in terms of params:
def SwapCaseAndCenter(*kwargs):
if upper_or_lower == "upper":
print a_string.center(center_num).upper()
if upper_or_lower == "lower":
print a_string.center(center_num).lower()
a_string = raw_input("Give m
#This is the actual code:
def SwapCaseAndCenter(a_string, upper_or_lower = None):
if upper_or_lower == "upper":
print a_string.center(center_num).upper()
if upper_or_lower == "lower":
print a_string.center(center_num).lower()
a_string = raw_input(
Algorithm it, and look at the instance below the function first where
variables are drawn in as raw input, and comments with # are just
comments, not part of the code:
def SwapCaseAndCenter(a_string, upper_or_lower = None):
#find if it's upper, and print
if upper_or_lower == "upper":
y not
after the things they follow? There is a long-standing convention in
this forum, and many others, and why let Microsoft ruin it for all of us?
>> Date: Thu, 18 Oct 2012 04:44:55 -0400
>> Subject: Re: [Tutor] Help Passing Variables
>> From: dwightdhu...@gmail.com
>> To
Thanks David. This has been helpful in understanding a bit more on how
parameters are passed through.
> Date: Thu, 18 Oct 2012 04:44:55 -0400
> Subject: Re: [Tutor] Help Passing Variables
> From: dwightdhu...@gmail.com
> To: dangu...@hotmail.com
> CC: tutor@python.org
>
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 stri
On 18/10/12 08:08, Daniel Gulko wrote:
The function calls for passing in two variables "a_string, width" but I
am still confused on this concept.
You just provide the list of input parameters when you define the function:
>>> def add(x,y):
... return x+y
...
>>> add(4,5)
9
I define add to t
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
10 matches
Mail list logo