Computer Science Canada

Can't get dice roller to work?

Author:  solarsparten [ Tue May 21, 2013 11:48 am ]
Post subject:  Can't get dice roller to work?

For some reason, this keeps out putting a score of zero after calculating 1000 rolls. It is supposed to add one to the score every time it goes through the loop. A little bit of help please?

http://www.mediafire.com/view/323vp9f37z5ll1w/twoTwelve3.py

Author:  ishidon [ Tue May 21, 2013 12:16 pm ]
Post subject:  Re: Can't get dice roller to work?

Everything in your code is correct except for one line.
Python:

        score == score + 1


So basically in this code block below,
Python:

while rollCount < 1000:
    rollCount = rollCount + 1
    diceTotal = dice()
    if diceTotal == 2 or diceTotal == 12:
        score == score + 1

you are rolling the dice 1000 times and if the two dice roll a sum of 2 or 12 you want to increase the score by 1.
However, what
Python:
score == score + 1
does is that it asks if score is equal to score + 1
I assume you are trying to increase the score by one.
To do this you want to use
Python:

score = score + 1

Basically, when you use two equals signs you are trying to compare two things (returns True of False) but when you use one equals sign you are assigning a value.


: