March 13th, 2005, 01:59 PM
Using simulations to solve a problem
I have been working on this darn problem for a while now and I was wondering if someone could help me out. This is a simulation for a raquetball game. I am trying to get my program to keep track of the results for a best of n (with n as a user input) matches. Here is what I have so far. I would really appreciate any help.
March 13th, 2005, 05:45 PM
Some initial impressions:
Originally Posted by adam12
1/ Don't use mixedCase; it makes your code look like Java. Use under_scores - ref PEP8.
2/ getInputs returns four items, but this line only unpacks three items:
(and you never pass m in, so the assignment to games in sim_n_games() will raise a NameError)
probA, probB, n = getInputs()
3/ Use augmented assignment
4/ Consider making a class SimulatedGame, which handles everything for running one game. Note that you only need to keep track of the one value - Increment if A wins, Decrement if B wins:
5/ Don't format text manually [in print_intro()] - use the textwrap module instead.
__init__(self, prob_a, prob_b):
a_wins = sum([SimulatedGame().play() for i in range(n)])
b_wins = n - a_wins
March 13th, 2005, 05:54 PM
Ok hydroxide thanks for the help I will try to make your suggested changes.