← back to unit
Medium
# basics variables
Why Types Matter: Mixing Text and Numbers
Types matter when combining values. You can't + a string and a number directly — Python won't guess what you mean. Convert the number to a string first with str():
name = "Sam"
points = 10
message = name + " has " + str(points) + " points."
print(message)
prints: Sam has 10 points.
Your turn: read a name, then a number of points. Using + (not an f-string this time), print exactly: <name> has <points> points.
💡 need a hint?
pyb-var-concat-convert.py🔒 given lines are locked — write your code in between
loading...