[Tutor] writing function changeColor

Aditi Pai aditipai1227 at gmail.com
Wed Jul 18 21:29:29 CEST 2012


Emile,

So far I have started with

def changeColor(pict,scale,color):

I was told to make different names for the float and integer (float = scale
and color= integer) and then I kept everything else the same, just to test
it out and see if that would work.

So it looks like this:

def changeColor(pict,scale,color):
  for p in getPixels(pict):
    value=getRed(p)
    setRed(p,value*.9)

Unfortunately I keep getting this error message:

The error was:changeColor() takes at least 3 arguments (1 given)
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type.
This means that you did something such as trying to pass a string to a
method that is expecting an integer.

On Wed, Jul 18, 2012 at 3:20 PM, Emile van Sebille <emile at fenx.com> wrote:

> On 7/18/2012 12:07 PM Aditi Pai said...
>
>  Hey Emile! Thanks for the advice. I think maybe I should have combined
>> the two parts of my email. The function is just called changeColor. I
>> don't actually want to change the color as much as alter the color.
>>
>
> I'm not sure there's a difference...
>
>
>  I'm working off of this example:
>>
>> def decreaseRed(picture):
>>     for p in getPixels(picture):
>>         value=getRed(p)
>>         setRed(p,value*0.5)
>>
>> Except for me, I am asked to also make the argument so that it accepts
>> an integer and a float.
>>
>
> So, if by that you mean that the function should accept two passed values,
> one an integer and the other a float, then your def line should look like:
>
> def changeColor(myint, myfloat):
>
> If, on the other hand, you want a single passed value that can be either
> an integer or a float you'd just have:
>
> def changeColor(myiint):
>
>
>
>  Not sure how to assign different colors and do that.
>>
>
>
> If the problem if adapting the example so that the function should accept
> both the picture thingy and a value to replace the hardcoded .5, your
> function def might look like:
>
> def changeColor(picture, myRedIntOrFloatVal):
>
> and then swap out the .5 for myRedIntOrFloatVal
>
> What have you written?
>
> Emile
>
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120718/a960c872/attachment.html>


More information about the Tutor mailing list