Reputation: 0 Apprentice
- New Members
- Active Posts:
- 8 (0.01 per day)
- 10-March 12
- Profile Views:
- Last Active:
- May 29 2012 12:48 PM
- OS Preference:
- Favorite Browser:
- Who Cares
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
Posts I've Made
Posted 14 Mar 2012I think what Jack was getting at is that:
while diceValue != initValue or 7:
Is probably not equating to what you think. It is saying if diceValue is not equal to initValue or "if the number 7 is false". Given that an number that isn't 0 is true, it will equate to:
while diceValue != initValue or True:
Which I'm guessing is why they win every time.
That makes sense! I revised all of the control structures in the script and it runs smoothly now. I appreciate everybody's help. =)
Anyway, the updated source code is:
The output also seems to agree with the craps winning probability (~49.3%):
Out of 1520 games, there were 745 wins. The probability of winning is 49.01% Out of 1000 games, there were 468 wins. The probability of winning is 46.80% Out of 500 games, there were 251 wins. The probability of winning is 50.20%
Posted 14 Mar 2012Try
while diceValue != initValue or diceValue == 7:
Wouldn't that just make the while loop keep looping until the diceValue == initValue? Correct me if I'm wrong, but that would yield the same results as while diceValue != initValue:.
If '7' is rolled, the while loop would just continue to re-roll for the initial value.
You need to throw the code into a debugger state so you can examine the value of the randomly generated number at this point.
I suspect that due to sheer speed of execution the new random is not actually a new number. Which would mean the second throw always matches the player's target point: Win!
Okay! I debugged my program with IDLE's debugger and some very bizarre things happened around here:
for i in range(numOfGameSim): diceValue = random.randrange(2, 13) initValue = diceValue if initValue == 7 or 11: numOfWins += 1
The program generated random numbers each run, but for some reason, executed these statements
if initValue == 7 or 11: numOfWins += 1
even if the condition was obviously false. After numOfWins += 1, the program went back to the top of the for loop and repeated the process for 'numOfGameSim' times adding 1 to numOfWins each time.
^^^ Full Source Code ^^^
Posted 14 Mar 2012Doesn't this mean the program will loop indefinatley until the player rolls a 7 or their point? Code won't continue to line 17 until the player wins.
Thanks for the reply! :)
while diceValue != initValue or 7: diceValue = random.randrange(2, 13)
Yes, this loop does continue to re-roll the die indefinitely until it hits the initial roll or a '7', but rolling a '7' would mean that the player loses the game. After re-rolling, the following if statements would determine which value the loop stopped at.
if diceValue == initValue: numOfWins += 1 # WIN else: numOfWins += 0 # LOSE
If the while loop stopped when it rolled the initial value, a win would be recorded. Otherwise, the win would not be recorded because the while loop stopped on a '7'.
I don't see how the player could always win if rolling a '7' during the while loop does not count as a win.
Posted 11 Mar 2012What do you mean by "how is it possible"? Do you mean how would you implement it in C++?
Sorry, my question wasn't clear. I guess I was asking for a breakdown on how Python interprets the for loop, but the C++ equivalents that you both provided was adequate in helping me understand. =)
It also helped that you pointed out that "collection" in for var in collection: must be iterable. I was under the mindset that the conditions only worked with number variables. Thanks!
Posted 10 Mar 2012It'll check the current working directory
Let me give you an example. let's say I don't have Python in my path (sue me, I don't) so I open up a prompt and I navigate to C:\Python27\ and typed in:
in this situation, Python would look for that file from C:\Python27\ because that is my current working directory.
On the other hand.
Let's say I navigate to C:\Users\Adam\Desktop\ and then ran this:
in this situation, it would look for the file in C:\Users\Adam\Desktop\ because that is my current directory.
Well wait a minute, let's say you have your pc set to run automatically when you double click it. Well, in that case it'll check your desktop. Here's a little script I wrote that you can use to confirm it. This script will print out the current working directory, which is where it'll look.
import os input(os.getcwd())
I'm assuming you use Linux or Windows.
I tried testing out both scenarios, and I get it now. Thanks! Also, does it make a difference whether I execute the script in the command prompt or in IDLE?
- Member Title:
- New D.I.C Head
- Age Unknown
- Birthday Unknown
Lenn0s hasn't added any friends yet.