[Tutor] 'number' strings error
alan.gauld@bt.com
alan.gauld@bt.com
Sun, 4 Mar 2001 17:25:06 -0000
> When I run this I get a 'cannot assign to literal' on the
> number strings.
Thats because you are using numbers as variables which is
not allowed. Try using one, two, three etc instead
> 1 = '1' #
> 2 = '2' # errors on these - try one = '1' instead
> 3 = '3' #
>
> l = [a, b, c]
> n = [1, 2, 3] # and this becomes [one,two,three]
# or just use ['1','2','3']...
>
> if l:
> l1 = random.choice(l)
> if l:
Since this is already tested above why not combine all the l
conditions like:
if l:
l1 = random.choice(l)
l2 = random.choice(l)
l3 = ...
l4 = ....
> if n:
> n1 = random.choice(n)
Or does random.choice change l during its action - eek! bad!
Alan G