TypeError: can't multiply sequence to non-int

Tyler Eaves tyler at tylereaves.com
Mon Nov 3 22:27:54 CET 2003


On Mon, 03 Nov 2003 13:33:15 -0700, Python wrote:

> Hello,
> 
> I am just learning Python and am going through some examples. I found
> one  very simple example I can't figure out. Here is the script:
> 
> # Enter a number to be squared
> x = raw_input("Enter a number: ")
> int(x)
> sq = x*x
> print sq
> 
> I am getting the following error:
> 
> Enter a number: 5
> Traceback (most recent call last):
>   File "db.py", line 6, in ?
>     sq = x*x
> TypeError: can't multiply sequence to non-int
> 
> Why is the function "int(x)" not changing the input to an integer?

It is. The thing is, it doesn't do it "in place".

replace that line with x = int(x)





More information about the Python-list mailing list