I have an integer called score, I turn it into a string and then try to get python to print a string of score plus a few other strings
score = 0
str(score)
variable = (" you have" + score + "points")
print(variable)
However it just tells me that score is still an integer, how do I fix this?
Strings and numbers are immutable, so str and int don't change the underlying value, but instead return a new value that you have to use.
For example:
score = 0
score = str(score)
variable = " you have " + score + " points"
print(variable)
or
score = 0
variable = " you have " + str(score) + " points"
print(variable)
However, using f-strings is probably better in this situation:
score = 0
variable = f" you have {score} points"
print(variable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With