[Tutor] trouble with "if"
kent37 at tds.net
Mon May 28 14:06:02 CEST 2007
adam urbas wrote:
> Very frustrating. What is a non-int and what is 'str'? Why can't it
> multiply the sequence? I guess I should include the program I'm using
> for these things.
These are more examples of the same kinds of errors you have been having.
Values in Python have a type. Some examples of types are int (integer),
float (floating point number) and str (string). Each type supports
different operations, for example you can't add 5 to 'this is a string'
or multiply 'a' * 'b' or even '5' * '6', both are strings.
> I'm having this problem with both of these attached. The messages above
> are from area.py. area.py is sort of a prototype of radiacir.py, a test
> version. You know, I should probably try that int trick, which I seem
> to have forgotten. And guess what that did it. It's amazing when you
> apply the things that you learn. Apparently I am quite absent minded.
> Well It seems I don't need any of this help anymore. Oh well. Thanks
You really should take the time to understand what is going on here.
int() is not a 'trick'. If you approach programming as trying a bunch of
tricks until you get something that seems to work, your programs will be
build on sand. If you take the time to understand and work with the
model that the programming language presents, you will have a much
easier time of it.
There are many good books and tutorials available. I recommend the book
"Python Programming for the absolute beginner" for someone with no
previous programming experience:
Quite a few beginners' tutorials are listed here:
Please, pick one of these resources, read it, write small programs that
use what you learn, come back here to ask questions when you get stuck.
More information about the Tutor