Current location: Hot Scripts Forums » Programming Languages » Other Languages » Need help with this Python simulation!!


Need help with this Python simulation!!

Reply
  #1 (permalink)  
Old 09-23-07, 01:22 PM
christophe007 christophe007 is offline
New Member
 
Join Date: Sep 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Need help with this Python simulation!!

I am a self paced new and very green Python student. I am trying to make my way through various Python problems but got stuck. I can’t seem to find anyone to turn to, but found your e-mail while I was on google for inspiration this morning…



The problems I am working though are very simple for anyone that has worked with Python but not so simple for someone that is new to this…

Here is problem that I have to solve:

Two hockey teams play eight times during the regular season. Team A wins five times and Team B wins the other three times. They meet in the playoffs in a best of seven series. Write a program that estimates the chances of Team B winning the series. A sample run of the program might look like this:

Are team B's chances better in a 1 game "series", a 3 game series, a 5 game series, or a 7 game series? What would team B's chances of winning a 51 game series be?

And here is the code that I have so far (keeping simple so I can understand the structure):

--------------

Python Code:
  1. import random
  2. SERIES = 1000
  3. game = 0
  4. series = 0
  5.  
  6. while series < SERIES:
  7.      teamA = random.randint (1,8)
  8.      teamB = random.randint (1,8)
  9.      teams = teamA + teamB
  10.  
  11.       if teams == 8:
  12.          game = game + 1
  13.       series = series + 1
  14.  
  15.  
  16. print 'In %2d simulated series Team B won %2d ' % (SERIES,game)
  17.  
  18. print 'so I estimate there is a',(game / 10),'% chance they will win
  19. the series.'


What am I doing wrong? What am I forgetting?? I hope you can help…

Chris

Last edited by UnrealEd; 09-25-07 at 02:21 PM. Reason: please use the [highlight=Python] tag when posting Python code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-23-07, 02:03 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Moved to Other Languages.
__________________
:: ImperialBB :: New version in the works! :: http://www.imperialbb.com ::

:: Have a question about the board? The Rules? An Infraction/Warning? :: Contact Form ::
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-25-07, 02:22 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Can you tell us what goes wrong?
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-12-09, 06:32 AM
chrishaizimsque chrishaizimsque is offline
New Member
 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
here u go i fixed your script for u

import random
SERIES = 1000
game = 1
series = 1

while series < SERIES:
teamA = random.randint (1,8)
teamB = random.randint (1,8)
teams = teamA + teamB


if teams == 8:
game = game + 1
series = series + 1


print "In %2d simulated series Team B won %2d % (SERIES,game)"

print "so I estimate there is a",(game / 20),"% chance they will win"
"the series.`"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
List of Python Tutorials and Resources digioz Other Languages 2 02-09-09 12:14 AM
Sockets: Java client, python server problem UnrealEd Everything Java 0 12-17-06 04:49 PM
using python in combination with php UnrealEd Other Languages 1 09-29-06 05:34 AM
Converting VB6 script to Python LAMPX The Lounge 0 04-11-06 06:51 PM
Python UnrealEd Hot Scripts Forum Questions, Suggestions and Feedback 2 03-27-06 04:38 PM


All times are GMT -5. The time now is 12:38 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.