Python Forum
TypeError: can't multiply sequence by non-int of type 'str'
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: can't multiply sequence by non-int of type 'str'
#1
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'
Reply
#2
The input values are strings. You have to convert them to integers
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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?"))
Reply
#4
how would you do that . i'm getting confused

oh ok .I ran the program and it worked .Thank you all
Reply
#5
(May-21-2018, 06:06 PM)j.crater Wrote:
width=int(input("what is the width?"))
height=int(input("what is the height?"))
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,207 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,099 May-07-2022, 08:40 AM
Last Post: ibreeden
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,026 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Why can't I explicitly call __bool__() on sequence type? quazirfan 11 4,541 Aug-20-2021, 06:49 AM
Last Post: Gribouillis
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 2,967 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,023 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 7,329 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  TypeError: 'type' object is not subscriptable Stef 1 4,441 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  TypeError: unhashable type: 'set' Stager 1 2,573 Jun-08-2020, 04:11 PM
Last Post: bowlofred
  TypeError: __repr__ returned non-string (type dict) shockwave 0 3,152 May-17-2020, 05:56 PM
Last Post: shockwave

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020