PRO
Tlachi
asked

Expert
Abhay Jajodia answered
Hi Tlachi,
Because pen_number is a number, and "Pens for each student: " is a string. In Python, you cannot join a string and a number using + unless you convert the number to a string first.
So this works:
print("Pens for each student: " + str(pen_number))
Another easy option is to use commas, which avoids str():
print("Pens for each student:", pen_number)
If you have more questions, I am here to help 😊
Python
This question was asked as part of the Getting started with Python course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer