A question I have...

Vlastimil Brom vlastimil.brom at gmail.com
Sat Oct 23 18:50:02 EDT 2010


2010/10/22 Joe Shoulak <joepshoulak at yahoo.com>:
> I'm trying to make a sports simulation program and so far everything has
> worked until I try entering:
>
> Score1 = (Team1Off + Team2Def)/2
>
> I get the error:
>
> TypeError: unsupported operand type(s) for /: 'str' and 'int'
>
> Can someone please explain to me what this means, why it doesn't work and
> what I can do to make it work?
>
> Thanks,
> Best Wishes,
> Joe Shoulak
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
The error message says, that the division operator "/" was applied
between string and integer number, which obviously don't work.
As the previous addition (Team1Off + Team2Def) didn't failed, both of
these items are probably strings.
If they are number literals, you can simply use int(Team1Off) + int(Team2Def)
Also note, that "/" means integer division by default (until python 2)
- i.e. the remainder would be discarded;
you can enforce float division by making at least one operand floating
point number: some_int/2.0

hth,
  vbr



More information about the Python-list mailing list