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 to a score of 15, but must be won by at least 2 points. If the scores are closer, the game can continue indefinitely. Your simulation should prompt the user for the service win probability of each player and loop until the one player wins. Print out the final scores.
can some one help me????
4 2805
I could be totally wrong on this, and I don't speak for anyone, but I have noticed the following, which I offer in a humble attempt to be helpful.
When something looks (may or may not be) like a homework assignment posted nearly straight out of the book it tends to get very little helpful attention. There is so much knowledge and willingness to help here it would be a shame to miss out. Suggestions, do any of the following... - Form an overall strategy and ask for comments.
- Break it into small tasks, write the code without regard to skill level and post for discussion. (use code tags)
- Ask specific questions regarding specific problems that don't seem to offer ready solution.
- Use terms and concepts that show evidence of having read the docs and learned some python.
i cant get the score up to 15 but it's adding both player's to make 15
can some help -
# volleyball.py
-
# Simulation of a volleyball game. Illustrates use of random
-
# numbers and functions to implement top-down design.
-
-
import random, random
-
-
def main():
-
Intro()
-
probA, probB, n = getInputs()
-
winsA, winsB = volleyball(n, probA, probB)
-
Summary(winsA, winsB)
-
-
def Intro():
-
# Prints an introduction to the program
-
print "This program simulates a game of volleyball between two"
-
print 'players called "player A" and "player B". The abilities of each player is'
-
print "indicated by a probability (a number between 0 and 1) that"
-
print "the player wins the point when serving. Player A always"
-
print "has the first serve.\n"
-
-
def getInputs():
-
#This take input from user
-
a = input("What is the prob. player A wins a serve? ")
-
b = input("What is the prob. player B wins a serve? ")
-
n = 15
-
return a, b, n
-
-
def volleyball(n, probA, probB):
-
winsA = winsB = 0
-
for i in range(n):
-
scoreA, scoreB = volleyball_one(probA, probB)
-
if scoreA > scoreB:
-
winsA = winsA + 1
-
else:
-
winsB = winsB + 1
-
return winsA, winsB
-
-
def volleyball_one(probA, probB):
-
serving = "A"
-
scoreA = 0
-
scoreB = 0
-
while not gameOver(scoreA == 15, scoreB == 15):
-
if serving == "A":
-
if (random.random() < probA):
-
scoreA = scoreA + 1
-
else:
-
serving = "B"
-
else:
-
if (random.random() < probB):
-
scoreB = scoreB + 1
-
else:
-
serving = "A"
-
if (scoreA >= 15 or scoreB >= 15):
-
if (abs(scoreA - scoreB) >=2):
-
break;
-
return scoreA, scoreB
-
-
def gameOver(a,b):
-
# a and b are scores for players in a volleyball game
-
# RETURNS true if game is over, false otherwise
-
return (a >= 15 and a - b >= 2) or (b >= 15 and b - a >= 2)
-
-
def Summary(winsA, winsB):
-
# Prints a summary of wins for each player.
-
n = winsA + winsB
-
print "\nGames simulated:", n
-
print "Wins for A: %d (%0.1f%%)" % (winsA, float(winsA)/n*100)
-
print "Wins for B: %d (%0.1f%%)" % (winsB, float(winsB)/n*100)
-
-
if __name__ == "__main__":
-
main()
Hi codie. My friend dshimer is right on point and since you seem to have copied your code directly from here, I'll have to suggest that other experts wait until you have made an honest effort at this problem to help with a solution.
they give this code to the student's to start the assignment it in the python book from john zelle if you look in there is it a racquetball game and we are told to change the code to play as a volley ball game
and way thank and sorry for taking your time
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joseph |
last post by:
Hi
I'm writing a commercial program which must be reliable. It has to do
some basic reading and writing to and from files on the hard disk,
and also to a floppy.
I have foreseen a potential...
|
by: Heather Stovold |
last post by:
Wow - deciding to program in python sure requires a lot of decisions!
So far:
I've decided on python for the programming language.
I've decided on wxpython for the GUI....
I've decided on...
|
by: James Fortune |
last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't
understand why people who know how to write code to completely replace
a front end do not write something that will automate...
|
by: vgame64 |
last post by:
Hi, I have been struggling with writing a program for a few hours. The
requirements are that: """You will be writing a program which will
determine whether a date is valid in
terms of days in that...
|
by: asif929 |
last post by:
I am trying to write a program which creates four triangles. The
program begins with prompting a user " Enter the size of triangles",
number from 1 to N is the size of four triangles For Example if...
|
by: RENEE |
last post by:
I Need help writing a program that will process payroll for small company with 26 employess, needs to store all employee name in sequential file along with address info, pay rate, number of...
|
by: lenest |
last post by:
I need help writing a program....
You are to write a python program to accomplish the following:
a.. Play a dice game of Craps using a random number generator to simulate
the roll of the...
|
by: adamurbas |
last post by:
ya so im pretty much a newb to this whole python thing... its pretty
cool but i just started today and im already having trouble. i
started to use a tutorial that i found somewhere and i followed...
|
by: rohitsripathi |
last post by:
i need help writing this program... i am in college and i do not have time do this right now as i need to study for another test....but this is due tonight...i will pay $5 if you accept to do it and...
|
by: alck1234 |
last post by:
Hi,
I need help on my mini project on object orientated programming. The
question goes like this:
A mini-mart has just installed a bar code reader to improve efficiency
at their checkouts....
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |