+ 6

TypeError: can only concatenate str (not "int") to str. Need help here.

def y_family(fname, lname, age): print(fname + " " + lname + " is " + age + " years old") y_family("Wukie", "Stephanie", 23)

1st Jul 2020, 11:48 AM
Apongpoh Gilbert
Apongpoh Gilbert - avatar
4 Respostas
+ 6
As long as you go for print() the output, you don't need to do any conversion. Just use a comma to separate all vars and strings like demonstrated in this sample: def y_family(fname, lname, age): print(fname, lname, 'is', age, 'years old') y_family("Wukie", "Stephanie", 23)
1st Jul 2020, 2:10 PM
Lothar
Lothar - avatar
+ 4
Convert age into string..as shown below def y_family(fname, lname, age): print(fname + " " + lname + " is " + str( age) + " years old") y_family("Wukie", "Stephanie", 23)
1st Jul 2020, 11:56 AM
ANJALI SAHU
+ 3
Apongpoh Gilbert You need to do str(age) while concatenate with string.
1st Jul 2020, 11:52 AM
A͢J
A͢J - avatar
+ 2
Thanks
17th Feb 2021, 11:55 PM
Apongpoh Gilbert
Apongpoh Gilbert - avatar