473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

''' 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()

Oct 26 '06 #1
3 2009
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

Oct 26 '06 #2
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
Oct 26 '06 #3
"Arun Nair" <na*******@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
''' 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
Oct 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Natehop | last post by:
I've been attempting to design an n-tiered framework leveraging .NET's strongly typed Dataset. My Framework will serve as the foundation to several client apps from Windows applications to web...
2
by: Andreas Schmitt | last post by:
Hi, Sorry for posting in German before, totally forgot about that when I was pasting this in here from another German newsgroup I was writing to, trying to get help I am programming a simple...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
1
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
22
by: noridotjabi | last post by:
Okay. I'm quite embarased to be asking this but I cannot seem to get files to work. I don't know what the problem is. Is there something wrong with this: (file related) #include <stdio.h>...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
31
by: louishong | last post by:
3rd time posting this as the first two simply disappeared! Here's the issue: We currently run an Access application in the West Coast for tracking resource centric data. For those located in the...
4
by: codie | last post by:
Design and implement a program that simulates a single volley ball game. In volleyball, only the serving team can score, and if the receiving team win the rally, they gain the serve. Games are played...
3
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/thinking-outside-the-box-with-python/ . Introduction: I...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.