[Tutor] Stuck on error

Alan Gauld alan.gauld at btinternet.com
Fri Dec 20 19:32:17 CET 2013


On 20/12/13 16:36, NZHacker1 . wrote:
> I'm trying to make a lottery in python and i keep getting this error.
> Cant assign to operator.(Mega Millions, line 47)

Please always send the full error message not just the last part.
There is a lot of useful data missing here.

> Here's the code.
>
> import random
>
> for i in range(1):
>      RN1 = random.randint(1,75)

Why do you have a for loop if you are only doing it once?
Just assign the value directly

> x = raw_input('Money in pennys.')
> Plays = int(x) * 100
> plays = int(x) * 100
> z = 0
> Game = ('Game')

You don;t need the parens here, they aren't doing anything.

> while Plays != 0:
>      Plays = Plays - 1
>      z = z + 1
>      for i in range(1):
>          N1 = random.randint(1,75)
>      for i in range(1):
>          N2 = random.randint(1,75)

Again, looping over range(1) is pointless.

>      Game + z = N1 + N2 + N3 + N4 + N5 + MB

Here is the error. You cannot assign a value(N1+N2+...)
to an expression (Game + z). In fact I'm not even sure
what you thought that might do?

Are you trying to compare the values of the two expressions?
In which case you need to use == instead of =. But then it would
still be pointless because you don't store or use the boolean
outcome. What are you trying to achieve in that line?

> z = 0
> while plays != 0:
>      Plays = Plays - 1
>      z = z + 1
>      print(Game + str(z))

This is an infinite loop. You are testing the value of plays
(lower case) but modifying the value of Plays (Capitalised)
Because plays is never changed the loop runs forever.

It might help to explain how you think the program should
work and then we can offer some ideas.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list