Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Can't get dice roller to work?
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
solarsparten




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
ishidon




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: