Re: [Tutor] error message questions

2007-05-27 Thread Alan Gauld
"adam urbas" <[EMAIL PROTECTED]> wrote in

> Hello all,I was wondering if there would be someone who
> would be able to give me a list of error messages and
> their meanings.

The errors are actually self explanatory - no really! - once
you undestandd the basic concepts. But to understand
those you will need to go back to basics.

I suggested in an earlier post that you read my Raw Materials topic
which discusses data and types. Did you do that?

Also the Talking to the User illustrates the use of raw_input,
you could usefully read that too. it discusses using the Python
conversion functions to get the right input values from raw_input..

> It says:can't multiply sequence by non-int of type 'str'

Which means Python cannot multiply the two types of data
you are giving it. You need to convert those values to the compatible
types.

> can't multiply sequence by non-int of type 'float'

Same thing, you have a sequence type on one side
(probably a string but could be a list or tuple?) and a float
on the other. You need to turn the sequence into something
that a float can multiply - either another float or an int (or
a complex or decimal if you feel really picky).

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message questions

2007-05-27 Thread Rikard Bosnjakovic
On 5/27/07, adam urbas <[EMAIL PROTECTED]> 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/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor