I'm currently using singpath.com to practice my python, but I face an issue with a problem:
The expected result is:
>>>CurryPuff(3)
3.60
>>>CurryPuff(3,'Fish')
4.2
This is something I tried:
def CurryPuff(x,typePuff):
if(typePuff==''):
return x*1.2
if(typePuff=='Fish'):
return x*1.4
But it give me this error:
TypeError: CurryPuff() takes exactly 2 arguments (1 given)
I had try googling on this but I'm not really very sure what is the key word to use, so hopefully can get help from here.
Thanks.
You can't call a function with 1 argument if it expects 2, as CurryPuff()
does. However, you can define a default argument that is used if no argument is passed:
def CurryPuff(x, typePuff=None):
if typePuff is None:
# and so on...
You can do this with any value for any argument. You may only omit arguments if a default value is defined.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.