I am currently working on the probability project and I am having issues with my logic. Here is the repl: https://replit.com/@Michael_Nicol/Probability-Calculator#prob_calculator.py
The section of the code I am having the most trouble with is the experiment function
My logic for experiment draw is that the draw fails if one of the colors drawn is not in expected or the amount drawn does not exactly match each color.
I put some print statements to understand the code better for each draw:
Formatted Drawn Contents:
{'green': 2, 'blue': 1, 'red': 1}
Wanted for Experiment
{'blue': 2, 'green': 1}
- Not equal: green 2 1
- Not equal: blue 1 2
- Not in: red dict_keys(['blue', 'green'])
Total Success: 0
Here is part of the code that controls part of this logic. Looking at the repl.it is best to understand the context, but the fault seems to be logical more than anything. I did 2,000 draws and not one passes multiple times. Is my approach wrong?
success = True
# Loop through the drawn contents
for colorKey in dict.keys(drawOutputDir):
# If the color we drew was not expected.
if (colorKey not in dict.keys(expected_balls)):
expected_flag = False
print("- Not in: ", colorKey," ", dict.keys(expected_balls))
# Otherwise, if the amount drew for the color is not the amount expected for that color
elif drawOutputDir[colorKey] is not expected_balls[colorKey]:
print("- Not equal: ",colorKey," ", drawOutputDir[colorKey], " ",expected_balls[colorKey])
expected_flag = False
else:
print("Made it through: ",colorKey)
# If any color fails, the entire draw is a failure
if expected_flag:
success+=1