. Advertisement .
..3..
. Advertisement .
..4..
How to solve the problem – typeerror: must be str, not int? I have the sample detail:
if verb == "stoke":
if items["furnace"] >= 1:
print("going to stoke the furnace")
if items["coal"] >= 1:
print("successful!")
temperature += 250
print("the furnace is now " + (temperature) + "degrees!")
^this line is where the issue is occuring
else:
print("you can't")
else:
print("you have nothing to stoke")
While I was running it, I found the warning message:
Traceback(most recent call last):
File "C:\Users\User\Documents\Python\smelting game 0.3.1 build
incomplete.py"
, line 227, in <module>
print("the furnace is now " + (temperature) + "degrees!")
TypeError: must be str, not int
That is my question in my midterm exam, and it is urgent. I searched the solutions on some websites, but I didn’t get it. I may miss any line or other changes. I appreciate your assistance!
The cause:
You have got this error because you are attempting to write integer values in your program but it is invalid, because it requires string values.
Solution:
Before concatenating, you have to change
int
tostr
by the following command:Python offers many ways to format strings.
.format()
has a new style that supports rich formatting.Specifier for the
%
old style format:Py 3.6 with the new
f""
format stringsOr using
print()
s defaultsep
arator:The least effective way to construct a string is by concatenating it with
str()
.Oder
join()
ing it