christophe007
09-23-07, 01:22 PM
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):
--------------
import random
SERIES = 1000
game = 0
series = 0
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 / 10),'% chance they will win
the series.'
What am I doing wrong? What am I forgetting?? I hope you can help…
Chris
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):
--------------
import random
SERIES = 1000
game = 0
series = 0
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 / 10),'% chance they will win
the series.'
What am I doing wrong? What am I forgetting?? I hope you can help…
Chris