Calling Functions Python

name = 6
age = 2

def dog_years(name, age):
return name+“, you are “+ (age * 7)+” years old in dog years”

print(dog_years(name, age))

hey guys! im just wondering why or how to call the function and get the desired output for dog years when i say print because its not working.

what should i write instead?

Please use the </> to format your code.

What’s your error message say? Do you get a Type Error?

  • name = 6 ?
  • and, double check your return for errors.

Hint: Play around with the code to see what happens. And, it might be a good idea to back and re-read what the lesson says about concatenation between two different types of objects.

1 Like

It is not possible to add integer to string.

name = 'Doggy'        # name is string
age = 5               # age is integer
result = name + ' ' + age   # this will cause error, we can not add string to integer
result = name + ' ' + str(age)    # integer is converted to string, it will work

In your example name and age are integers (btw. why name is number 6? :slight_smile: ). Function str is built-in function which converts object to string. You only need to change one line and it will work:

return str(name) + ', you are '+ str(age * 7) + ' years old in dog years'
1 Like

Yeah your name should probably be a string in this case.

Also for readability
return name+“, you are “+ (age * 7)+” year-old in dog years”

1 Like