• Register
1 vote
320 views

Problem:

 

if verb == "stoke":

        if items["heat"] >= 1:
            print("going to stoke the furnace")

            if items["coal"] >= 1:
                print("successful!")
                temperature += 250 
                print("the heat is now " + (temperature) + "degrees!")
                           
            else:
                print("you can't")

        else:
            print("you have nothing to stoke")

 

I don’t know know what’s wrong with my code. The resulting error comes up as the following:

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 heat is now " + (temperature) + "degrees!")
    TypeError: must be str, not int

I must recognize your effort.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

Python can't automatically convert integer variable to string. You need to explicitly convert future variable to str.

So,

print("the heat is now " + str(temperature) + "degrees!")

cast this portion to str. Then the code should execute with no errors.

 

13 9 6
94,240 points

Related questions

0 votes
1 answer 108 views
108 views
I was looking for a way to run an external process from python script and print its stdout messages during the execution. The code below works, but prints no stdout output during runtime. When it exits I am getting the following error: sys.stdout.write(nextline) TypeError:must ... .stdout.write(nextline) sys.stdout.flush() output = p.communicate()[0] exitCode = p.returncode I am using python 3.3.2
asked Oct 24, 2020 psandprop 2.4k points
0 votes
1 answer 41 views
41 views
Problem: Hello! I am a beginner. I just moved from Java to Python programming just recently. I am learning the syntax of Python. I am trying to print the multiplication table using the while loop. I have written the following program in an attempt to do that: number ... to str implicitly I do not have any clue regarding this error. Can anybody here help me solving this error? I would be thankful.
asked Jan 8 Code Learner 9.2k points
0 votes
1 answer 38 views
38 views
Problem: Hi! I am new to the world of programming. I am trying to multiply two numbers that will be entered by the user. I wrote the following program: number1 = input("Enter first number: ") number2 = input("Enter second number: ") print(number1," * ",number2," = ", ... = ",number1*number2) TypeError: can't multiply sequence by non-int of type 'str' I have no idea what I am doing wrong. Any help?
asked Dec 21, 2020 Code Learner 9.2k points
0 votes
1 answer 26 views
26 views
Problem: I am a newbie to the world of Python, and I am so confused about the data types in Python. I am trying to run the following program: obtained_marks = input("Enter the marks your child obtained: ") total_marks = 100 difference = total_marks - ... cannot see any evident reason for this error. I cannot identify where I am trying to subtract a string from an integer. Any helper?
asked Dec 17, 2020 Code Learner 9.2k points
0 votes
1 answer 24 views
24 views
Problem: Hello! I am new to programming and I am trying to run following code: def division(number): if(number/4 >= 1): print("Divisible by 4") else: print("Not divisible by 4") dividend = input("Enter dividend: ") division(dividend) What I am trying to do is ... 'int' I cannot see any obvious reason of this error. If any of you could identify the reason, it would be very helpful for me. Thanks!
asked Dec 17, 2020 Code Learner 9.2k points
0 votes
1 answer 37 views
37 views
Problem: On the last line, I got this error: builtins.TypeError: must be str, not bytes File "C:\PythonExamples\XmlReportGeneratorExample.py", line 29, in <module> doc.write(outFile) File "c:\Python32\Lib\site-packages\lxml\etree.pyd", line 1853, in lxml.etree._ElementTree.write (src/ ... etree.c:89527) I've installed Python 3.2, and I've installed lxml-2.3.win32-py3.2.exe. On Python 2.7 it works.
asked Jan 9 Mashhoodch 13k points
1 vote
1 answer 6 views
6 views
Problem: Help is required from some body to convertthis. Typeerror: can't convert 'float' object to str implicitly.
asked Mar 28 PkGuy 13.1k points
0 votes
1 answer 22 views
22 views
Problem: I am working on exercise 41 in learnpythonthehardway and keep getting the error: Traceback (most recent call last): File ".\url.py", line 72, in <module> question, answer = convert(snippet, phrase) File ".\url.py", line 50, in convert result = result ... TypeError: Can't convert 'bytes' object to str implicitly I am using python3 while the books uses python2, so I have made some changes.
asked Feb 23 Mashhoodch 13k points
0 votes
1 answer 27 views
27 views
Problem: Hi there! I am a new programmer, and I have started programming in Python just recently. I am facing a little difficulty in getting used to Python syntax. I am trying to run the following code: pi = "3.14"; floating = float(input("Enter a floating-point ... to subtract a value from the value of pi and print the answer. Could anybody here please point out the mistake I am making? Thanks!
asked Jan 8 Code Learner 9.2k points