[Tutor] error message questions
Rikard Bosnjakovic
rikard.bosnjakovic at gmail.com
Sun May 27 19:53:18 CEST 2007
On 5/27/07, adam urbas <adamurbas at hotmail.com> wrote:
> It says:
>
> can't multiply sequence by non-int of type 'str'
The reason is that raw_input() returns a string. What you are trying
to do is multiply a string with a string, which - in Python - is an
illegal operation.
What you want to do is to convert the read value from raw_input() to
an integer, and then multiply. You convert with the function int(). So
if you change the two upper lines of your code test.py to
height = int(raw_input("enter height:"))
width = int(raw_input("enter width:"))
then the multiplication will work. It will - however - not work if you
don't enter a numerical value, because int() will fail for everything
else than numericals.
HTH.
--
- Rikard - http://bos.hack.org/cv/
More information about the Tutor
mailing list