TypeError: can't multiply sequence by non-int of type 'str' - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: TypeError: can't multiply sequence by non-int of type 'str' (/thread-10452.html) |
TypeError: can't multiply sequence by non-int of type 'str' - pythonnoob1234 - May-21-2018 Hi i'm new to python and i just don't understand this error Python code width=input("what is the width?") height=input("what is the height?") area=width*height print("The area is" ,area) ERROR what is the width? 2 what is the height? 3 Traceback (most recent call last): line 3, in <module> area=width*height TypeError: can't multiply sequence by non-int of type 'str' RE: TypeError: can't multiply sequence by non-int of type 'str' - wavic - May-21-2018 The input values are strings. You have to convert them to integers RE: TypeError: can't multiply sequence by non-int of type 'str' - j.crater - May-21-2018 input returns a string, so with area=width*height you are really multiplying two strings. You need to convert the inputs (strings) to numbers first, for example integer: width=int(input("what is the width?")) height=int(input("what is the height?")) RE: TypeError: can't multiply sequence by non-int of type 'str' - pythonnoob1234 - May-21-2018 how would you do that . i'm getting confused oh ok .I ran the program and it worked .Thank you all RE: TypeError: can't multiply sequence by non-int of type 'str' - wavic - May-21-2018 (May-21-2018, 06:06 PM)j.crater Wrote:width=int(input("what is the width?")) height=int(input("what is the height?")) |