473,385 Members | 1,546 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,385 software developers and data experts.

i need help writing a program

8
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????
May 17 '07 #1
4 2805
dshimer
136 Expert 100+
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.
May 17 '07 #2
codie
8
i cant get the score up to 15 but it's adding both player's to make 15
can some help

Expand|Select|Wrap|Line Numbers
  1. # volleyball.py
  2. # Simulation of a volleyball game. Illustrates use of random
  3. # numbers and functions to implement top-down design.
  4.  
  5. import random, random
  6.  
  7. def main():
  8.     Intro()
  9.     probA, probB, n = getInputs()
  10.     winsA, winsB = volleyball(n, probA, probB)
  11.     Summary(winsA, winsB)
  12.  
  13. def Intro():
  14.     # Prints an introduction to the program
  15.     print "This program simulates a game of volleyball between two"
  16.     print 'players called "player A" and "player B".  The abilities of each player is'
  17.     print "indicated by a probability (a number between 0 and 1) that"
  18.     print "the player wins the point when serving. Player A always"
  19.     print "has the first serve.\n"
  20.  
  21. def getInputs():
  22.     #This take input from user
  23.     a = input("What is the prob. player A wins a serve? ")
  24.     b = input("What is the prob. player B wins a serve? ")
  25.     n = 15
  26.     return a, b, n
  27.  
  28. def volleyball(n, probA, probB):
  29.     winsA = winsB = 0
  30.     for i in range(n):
  31.         scoreA, scoreB = volleyball_one(probA, probB)
  32.         if scoreA > scoreB:
  33.             winsA = winsA + 1
  34.         else:
  35.             winsB = winsB + 1
  36.     return winsA, winsB
  37.  
  38. def volleyball_one(probA, probB):
  39.     serving = "A"
  40.     scoreA = 0
  41.     scoreB = 0
  42.     while not gameOver(scoreA == 15, scoreB == 15):
  43.         if serving == "A":
  44.             if (random.random() < probA):
  45.                 scoreA = scoreA + 1
  46.             else:
  47.                 serving = "B"
  48.         else:
  49.             if (random.random() < probB):
  50.                 scoreB = scoreB + 1
  51.             else:
  52.                 serving = "A"
  53.         if (scoreA >= 15 or scoreB >= 15):
  54.             if (abs(scoreA - scoreB) >=2):
  55.                 break;
  56.     return scoreA, scoreB
  57.  
  58. def gameOver(a,b):
  59.     # a and b are scores for players in a volleyball game
  60.     # RETURNS true if game is over, false otherwise
  61.     return (a >= 15 and a - b >= 2) or (b >= 15 and b - a >= 2)
  62.  
  63. def Summary(winsA, winsB):
  64.     # Prints a summary of wins for each player.
  65.     n = winsA + winsB
  66.     print "\nGames simulated:", n
  67.     print "Wins for A: %d (%0.1f%%)" % (winsA, float(winsA)/n*100)
  68.     print "Wins for B: %d (%0.1f%%)" % (winsB, float(winsB)/n*100)
  69.  
  70. if __name__ == "__main__":
  71.     main()
May 18 '07 #3
bartonc
6,596 Expert 4TB
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.
May 18 '07 #4
codie
8
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
May 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

48
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...
13
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...
19
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...
13
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...
12
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...
0
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...
1
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...
12
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...
7
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...
5
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....
1
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...
0
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...
0
isladogs
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.