Reputation: 47
I have tried without the type, with float - what is my newby mistake here?
def calcAge(age):
return int(birth=20 - age)
age = int(input("What age will you turn this year? "))
birth = int(calcAge(age))
RESULT:
What age will you turn this year? 54
Traceback (most recent call last):
File "D:/DSDJ/My files/ParameterPassReturnTest.py", line 13, in <module>
birth = int(calcAge(age))
File "D:/DSDJ/My files/ParameterPassReturnTest.py", line 8, in calcAge
return int(birth=20 - age)
TypeError: 'birth' is an invalid keyword argument for int()
Process finished with exit code 1
Upvotes: 0
Views: 2513
Reputation: 51
The int call is a function. By saying "birth=20-age" you are basically saying, "The argument birth is (20-age)". The function is looking for that argument but cannot find it and that is why you get that error. Just do
def calcAge(age):
return 20 - int(age)
age = int(input("What age will you turn this year? "))
birth = calcAge(age)
Upvotes: 0
Reputation: 4869
The problem is on this line:
return int(birth=20 - age)
int()
is a method that takes an argument. You're giving it a named argument birth
, but that's not what it expects. Remove the name, to this, gets you closer:
return int(20 - age)
Unfortunately age
is not an int. I think what you want is this:
return 20 - int(age)
You can then remove the int()
call a few lines later.
Upvotes: 1