Darren Williams wrote:
> Ok, now i've modified my script but am getting another error, i've 
> commented a few useless (hopefully) lines out -
>
> #!/usr/bin/env python
>
> import cgitb; cgitb.enable()
> import cgi
>
>
[snip]
>         17     while usedPockets > totalJunkies - labSpace * 17:
>
>         18         Tokens = Tokens + 1
>
>         19         usedPockets = (usedPockets - totalJunkies + 
> labSpace) * 17
>
>      usedPockets = '192000', totalJunkies = '200', labSpace = '0'
>
> TypeError: unsupported operand type(s) for -: 'str' and 'str'
>      args = ("unsupported operand type(s) for -: 'str' and 'str'",)
>

What does "dog" - "cat" mean?  Similarly, what does "100" - "12" mean?  
It's not the same in Python as 100 - 12, because those are numbers, 
"100" and "12" are strings which happen to represent numbers.

You need to coerce those strings into integers, maybe like this:

usedPockets = int(form["usedPockets"].value)

When you do that, you'll probably need to catch any exception that could 
occur if the string can't be converted.

>
>
> It's confused me - it says I can't subtract a string from a string but 
> then gives the value's of the variables (that I randomly entered into 
> the form) at the bottom - usedPockets = '192000', totalJunkies = 
> '200', labSpace = '0'
>

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

Reply via email to