Can any one help with solving this program it just doesnt take probability of the second team

Discussion in 'Python' started by Arun Nair, Oct 26, 2006.

  1. Arun Nair

    Arun Nair Guest

    ''' Can anyone help me with this program it just takes probability of
    the first team and runs the program doesnt takes the probability of the
    second team even though specified'''

    from random import *

    def volleySimulation():
    printInstructions()
    probA, probB, n = getInputs()
    winA, winB = simGames(n, probA, probB)
    printSummary(winA, winB)

    def printInstructions():
    print "This program stimulates a game of Volley Ball between two
    teams i.e. Team A and Team B"
    print "The abilities of each team is indicated by a probability
    that determines which team wins the points."
    print "We assume that Team A always serves first"

    def getInputs():
    print "Enter the probability for both team winning the serve in
    between 0 and 1"
    probA = input("Enter the probability of Team A winning a serve")
    probB = input("Enter the probability of Team B winning a serve")
    n = input("Enter the number of games that you want to simulate:")
    return probA, probB, n

    def simGames(n, probA, probB):
    winA = 0
    winB = 0
    for i in range(n):
    scoreA, scoreB = simGame(probA, probB)
    if scoreA > scoreB:
    winA = winA + 1
    else:
    winB = winB + 1
    return winA, winB

    def simGame(probA, probB):
    scoreA = 0
    scoreB = 0
    serving = "A"
    while not gameOver(scoreA, scoreB):
    if serving == "A":
    if random() < probA:
    scoreA = scoreA + 1
    else:
    serving == "B"
    else:
    if random() < probB:
    scoreB = scoreB + 1
    else:
    serving == "A"
    return scoreA, scoreB

    def gameOver(a, b):
    return (a == 15 or b == 15) and ((a - b) > 2 ) or ((a - b) < -2)

    def printSummary(winA, winB):
    n = winA + winB
    print "Games simulated:", n
    print "Wins for A: %d (%0.1f%%)" % (winA, float(winA)/n*100)
    print "Wins for B: %d (%0.1f%%)" % (winB, float(winB)/n*100)

    volleySimulation()
     
    Arun Nair, Oct 26, 2006
    #1
    1. Advertising

  2. Arun Nair

    Peter Otten Guest

    Arun Nair wrote:

    > ''' Can anyone help me with this program it just takes probability of
    > the first team and runs the program doesnt takes the probability of the
    > second team even though specified'''


    > def simGame(probA, probB):
    > scoreA = 0
    > scoreB = 0
    > serving = "A"
    > while not gameOver(scoreA, scoreB):
    > if serving == "A":
    > if random() < probA:
    > scoreA = scoreA + 1
    > else:
    > serving == "B"


    Hint: this is not an assignment.

    > else:
    > if random() < probB:
    > scoreB = scoreB + 1
    > else:
    > serving == "A"


    Same thing.

    > return scoreA, scoreB


    Peter
     
    Peter Otten, Oct 26, 2006
    #2
    1. Advertising

  3. Arun Nair

    Arun Nair Guest

    Thanks a ton peter its working.


    Peter Otten wrote:
    > Arun Nair wrote:
    >
    > > ''' Can anyone help me with this program it just takes probability of
    > > the first team and runs the program doesnt takes the probability of the
    > > second team even though specified'''

    >
    > > def simGame(probA, probB):
    > > scoreA = 0
    > > scoreB = 0
    > > serving = "A"
    > > while not gameOver(scoreA, scoreB):
    > > if serving == "A":
    > > if random() < probA:
    > > scoreA = scoreA + 1
    > > else:
    > > serving == "B"

    >
    > Hint: this is not an assignment.
    >
    > > else:
    > > if random() < probB:
    > > scoreB = scoreB + 1
    > > else:
    > > serving == "A"

    >
    > Same thing.
    >
    > > return scoreA, scoreB

    >
    > Peter
     
    Arun Nair, Oct 26, 2006
    #3
  4. Arun Nair

    Paul McGuire Guest

    "Arun Nair" <> wrote in message
    news:...
    > ''' Can anyone help me with this program it just takes probability of
    > the first team and runs the program doesnt takes the probability of the
    > second team even though specified'''
    >
    > from random import *
    >
    > def volleySimulation():
    > printInstructions()
    > probA, probB, n = getInputs()
    > winA, winB = simGames(n, probA, probB)
    > printSummary(winA, winB)
    >
    > def printInstructions():
    > print "This program stimulates a game of Volley Ball between two
    > teams i.e. Team A and Team B"


    While I was "stimulated" by reading this post, I think you mean "simulates"
    here. :)

    -- Paul
     
    Paul McGuire, Oct 26, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arun Nair
    Replies:
    6
    Views:
    301
    Fredrik Lundh
    Oct 27, 2006
  2. Replies:
    4
    Views:
    1,078
    Default User
    Oct 23, 2006
  3. Replies:
    3
    Views:
    461
    alex23
    May 27, 2008
  4. Lionel
    Replies:
    14
    Views:
    1,200
  5. Menny Menahem
    Replies:
    0
    Views:
    140
    Menny Menahem
    Jun 23, 2010
Loading...

Share This Page