I'm trying to find out how many times you have to throw the dice to get on file 5 100 times(board is played from 0 to 5). This is how I tried(I know the answer is 690 but I don't know what I'm doing wrong).
from random import *
seed(8)
five = 0
count = 0
add = 0
while five < 100:
count = count + 1
print(randint(1,6))
add = add + randint(1,6)
if add % 5 == 0 :
five = five + 1
else: add = add + randint(1,6)
print(count)
This is the code I think you were trying to write. This does average about 600. Is it possible your "answer" came from Python 2? The random seed algorithm is quite likely different.
from random import *
seed(8)
five = 0
count = 0
add = 0
while five < 100:
count += 1
r = randint(0,5)
if r == 5:
five += 1
else:
add += r
print(count, add)
You're adding a second dice throw every time you don't get on 5, this makes the probability distribution irregular (i.e. advancing by 7 will be more probable (1/6) than any other value, e.g. 1/9 for 5) so your result will not be the same as counting single throws.
BTW there is no fixed result for this, just a higher probability around a given number of throws. However, given that you seeded the random number generator with a constant, every run should give the same result. And it should be the right one if you don't double throw the dice.
Here is an example of the process that arrives at 690:
import random
random.seed(8)
fiveCount = 0
throwCount = 0
position = 0
while fiveCount < 100:
position = (position + random.randint(1,6)) % 6
throwCount += 1
fiveCount += position == 5
print(throwCount) # 690
Other observations:
Updating the position wraps around using modulo 6 (there are 6 positions from 0 to 5 inclusively)
Your check of add%5 == 0 does not reflect this. It should have been add%6 == 5 instead but it is always preferable to model the computation as close as possible to the real world process (so keep the position in the 0...5 range)
I've created a function winProbability(ra, rb, n) and I want to simulate n games in order to estimate the probability that a player with the ability ra will win a game against a player with ability rb
I'll show the code I've done so far. If this seems like a easy issue it's because I am new to coding.
import random #import random allows for the use of randomly generated numbers
def game(ra, rb): #this function game sets out the way the game runs
p_a_point = ra/(ra+rb) #this line of code determines the probability that
#player a wins any given point
a_points = 0 #the amount of points player a has is defaulted to 0
b_points = 0 #the amount of points player b has is defaulted to 0
score_to_win = 11 #the winning score is defaulted to 11
while (a_points < score_to_win and b_points < score_to_win) or abs (a_points - b_points) < 2: #while player a's points and player b's points are less than the winning score:
p_b_point = random.random()#the probability b wins a point is set the a random value between 0 and 1
if p_b_point < p_a_point: #is the probability b wins a point is less than the probability a wins a point:
a_points = a_points + 1 #a wins 1 point
else: #if player a doesn't win a point:
b_points = b_points + 1 #b wins a point
return(a_points, b_points)#both players points are returned
print(game(70,30))#the function is called with two integer values as parameters
def winProbability(ra, rb, n):
To be honest from here I am unsure on how to go about this. I was thinking of doing a for loop so for example:
for n in game (ra, rb):
but I am unsure if I can use a previous function in this loop call. I'm also confused on how to calculate probabilities in code
The general aim is to call the function with two probabilities for example 70 and 30 and give a decimal answer for the probability player ra will win.
To previous commenters, I apologise for being vague before. I've never posted on here before.
See if this helps.
from random import randint, seed
seed()
rounds = input(" How many rounds will be played in the match? ")
print("\n Please enter skill levels as integers from 0 to 99.\n")
a = input(" What is the skill level of player 1? ")
b = input(" What is the skill level of player 2? ")
# Catch empty inputs
if not rounds: rounds = 10
if not a: a = 0
if not b: b = 0
# Python inputs are always strings. Convert them to integers.
rounds = int(rounds)
a = int(a)
b = int(b)
# If both skill levels are 0, set them to 1.
# (This will avoid a possible division by zero error.)
if a+b == 0: a = b = 1
# Catch and correct numbers that are too high.
if a > 99: a = 99
if b > 99: b = 99
# Convert integer skill levels to values between 0.0 and 0.99
a = a/100
b = b/100
print()
print(" Chance player 1 will win: "+str(int(100*a/(a+b)))+" percent.")
print(" Chance Player 2 will Win: "+str(int(100*b/(a+b)))+" percent.")
print()
for x in range(rounds):
roll = randint(0,999)/1000
print("roll =",roll, end =": ")
if roll <= a/(a+b): # <-- Compare roll to ratio of player skill levels.
print("Round "+str(x+1)+" Winner: Player 1")
else:
print("Round "+str(x+1)+" Winner: Player 2")
print()
this was my answer
import random
def winProbability(ra, rb, n):
winCount = 0 #used to count how many times 'a' won
probabilityRange = ra + rb
for i in range(n):
# pick a number between 0 and probabiilityRange
number = random.randint(0, probabilityRange)
# if number is < ra then 'a' won if number is > ra then 'b' won if number == ra then results in a draw
if number < ra:
winCount += 1
print ('win')
if number > ra:
print('loss')
if number == ra:
print ('draw') # draw doesn't count as win
return winCount*(100/n)
print (winProbability(10000,1,100000))
This prints the results of each game played, and returns the possibility that 'a' will win in percentile form.
My problem is: I have 12 players, with 3 of them being named A, B and C, respectively. 12 players are being divided into 2 groups, 6 people each. I need to calculate the probability of player A and B being in the same team, and player C being in thе eopposite one. Math is not my strongsuit, because im pretty sure this is not a hard thing to calculate, but i would be really grateful if you could help me with this one. Here is what i wrote so far:
import random
playersnumb = 12
players = list(range(12))
A = random.choice([x for x in range(12)])
B = random.choice([x for x in range(12) if x != A])
C = random.choice([x for x in range(12) if (x != A) and (x != B)])
random.shuffle(players)
team1 = (players[:6])
team2 = (players[6:])
if A in team1:
print("Player A is in team 1")
else:
print("Player A is in team 2")
if B in team1:
print("Player B is in team 1")
else:
print("Player B is in team 2")
if C in team1:
print("Player C is in team 1")
else:
print("Player C is in team 2")
Any help is appreciated.
I wrote a little bit based on your code. The idea is to loop multiple times over your test code, it is not 100% accurate, but i think good enough for you:
import random
def calculate(playercount: int = 12) -> bool:
players = list(range(playercount))
player_a = random.choice([x for x in range(playercount)])
player_b = random.choice([x for x in range(playercount) if x != player_a])
player_c = random.choice([x for x in range(playercount) if (x != player_a) and (x != player_b)])
random.shuffle(players)
team1 = (players[:playercount//2])
team2 = (players[playercount//2:])
# That are your "positive" events
return (player_a in team1 and player_b in team1 and player_c in team2) or\
(player_a in team2 and player_b in team2 and player_c in team1)
def calculate_all(runtimes: int = 100000) -> float:
counter = 0
# count all poyitive events
for i in range(runtimes):
if calculate():
counter += 1
# return how often they appeared, based on all tests
return counter / runtimes
print("The probability is about {} %".format(calculate_all() * 100))
The number of ways to fill 1 list of six total = 12!/(6! * 6!) comb(12,6)
The number of ways to fill a list of six (including A and B and not C) = 9!/(4! * 5!) comb(9, 4)
Also, want to find (not A and not B and C) = 9!/(5! * 4!) comb(9, 5)
>>> from math import comb
>>> comb(12, 6)
924
>>> comb(9, 4) + comb(9, 5)
252
>>> 252 / 924
0.2727272727272727
My task was to
'Write a function selectCoins that asks the user to enter an amount of money
(in pence) and then outputs the number of coins of each denomination (from £2 down
to 1p) that should be used to make up that amount exactly (using the least possible
number of coins). For example, if the input is 292, then the function should report:
1 × £2, 0 × £1, 1 × 50p, 2 × 20p, 0 × 10p, 0 × 5p, 1 × 2p, 0 × 1p. (Hint: use integer
division and remainder).'
def selectCoins():
twopound = 200
onepound = 100
fiftyp = 50
twentyp = 20
tenp = 10
fivep = 5
twop = 2
onep = 1
a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
g = 0
h = 0
money = int(input('Enter how much money you have in pence'))
while True:
if money >= twopound:
money = money - twopound
a = a + 1
elif money >= onepound:
money = money - onepound
b = b + 1
elif money >= fiftyp:
money = money - fiftyp
c = c + 1
elif money >= twentyp:
money = money - twentyp
d = d + 1
elif money >= tenp:
money = money - tenp
e = e + 1
elif money >= fivep:
money = money - fivep
f = f + 1
elif money >= twop:
money = money - twop
g = g + 1
elif money >= onep:
money = money - onep
h = h + 1
else:
money = 0
break
print(a,b,c,d,e,f,g,h)
I am new to programming so when I run this code it just inputs
'1 0 0 0 0 0 0 0' when I type 292 instead of what it should output.
Since you're new to coding, you should start writing the procedure you'd follow on paper, and then find out which tools you can use to automate this process.
Important
Read the full answer in order!
Don't fall for the temptation of reading the code right away.
The solutions I provide are hidden, but you can read them hovering your mouse over them or clicking on them (if you're using StackExchange mobile app, touch the "spoiler" link in each block).
The algorithm
What I'd do is:
Assume I have bins with coins, each bin labeled with the coin denomination.
The bins are sorted from the largest to the lowest denomination, and I always pick as much coins as I need from the highest denomination bin before moving to the next bin.
Write in a piece of paper the value for which I need to calculate the number of coins of each denomination I need.
Start with the first bin (the one holding the highest denomination).
Pick as many coins I need from that bin, in such a way that I don't "overshoot" the amount written on the piece of paper (notice that this number can be zero).
This can be done with an integer division; for example, if your value is 700 and the bin has denomination 200, you calculate the integer division 700 ÷ 200 = 3 (plus a remainder of 100)
Calculate the total amount of the coins I've picked.
Strike the value calculated in step 5 and write the remainder as a "new" value.
Since you've already calculated the integer division in step 4, you can calculate the remainder. You can also consider that there's a "Modulo" operator in most programming languages that will give you the remainder of an integer division right away. Using the above example, 700 mod 200 = 100, which reads "700 modulo 200 is 100", or "The remainder of the integer division 700 ÷ 200 is 100".
Move on to the next bin of coins.
Repeat from step 4 until I use all the bins or the value is zero.
Example
Suppose I start with a value of 292 and I have bins with the following denominations (already sorted from highest to lowest denominations):
| 200 | 100 | 50 | 20 | 10 | 5 | 2 | 1 |
+------+------+------+------+------+------+------+------+
| I | II | III | IV | V | VI | VII | VIII |
So, let's see what happens if I apply the algorithm above:
Write the value: 292
Start with the first bin (denomination: 200)
Pick 1 coin from the bin
The total amount picked from the bin is 200
The remainder is 92
Strike the previous value
The new value is 92
Move to the next bin (denomination: 100)
Pick 0 coins from the bin
The total amount picked from the bin is 0
The remainder is 92
Strike the previous value
The new value is 92
Move to the next bin (denomination: 50)
Pick 1 coin from the bin
The total amount picked from the bin is 50
The remainder is 42
Move to the next bin (denomination: 20)
Pick 2 coins from the bin
The total amount picked from the bin is 20
The remainder is 2
Move to the next bin (denomination: 10)
Pick 0 coins from the bin
The total amount picked from the bin is 0
The remainder is 2
Move to the next bin (denomination: 10)
Pick 0 coin from the bin
The total amount picked from the bin is 0
The remainder is 2
Move to the next bin (denomination: 5)
Pick 0 coin from the bin
The total amount picked from the bin is 0
The remainder is 2
Move to the next bin (denomination: 2)
Pick 1 coin from the bin
The total amount picked from the bin is 2
The remainder is 0
Done
Implementing this in Python
Python is an amazingly clear language, and makes this sort of tasks easy. So let's try to translate our algorithm to Python.
The toolbox
Assuming you're using Python 3.x, you'll need to know some operators:
The integer division operator (//): If you divide with just a single slash, you'll get the "real division" (e.g. 3 / 2 == 1.5), but if you use a double slash, you'll get the "integer division (e.g. 3 // 2 = 1)
The modulo operator (%): As explained above, this operator returns the remainder of a division (e.g. 7 % 4 == 3)
Used together, these operators will give you what you need on each step:
292 // 200 == 2
292 % 200 == 92
92 // 100 == 0
92 % 100 == 92
...
One useful characteristic of Python is that you can perform a "multiple assignment": You can assign multiple values to multiple variables in one single step:
# Initialize the value:
value = 292
# Initialize the denomination:
denomination = 200
# Calculate the amount of coins needed for the specified denomination
# and get the remainder (overwriting the value), in one single step:
coins, value = value // denomination, value % denomination
# ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
# | The remainder
# The number of coins
# (using integer division)
With this knowledge, we can write the solution:
Correcting your code
Remember: Read all of the above before revealing the solutions below.
def selectCoins():
twopound = 200
onepound = 100
fiftyp = 50
twentyp = 20
tenp = 10
fivep = 5
twop = 2
onep = 1
a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
g = 0
h = 0
money = int(input('Enter how much money you have in pence')) # Example: 292
# Calculate the number of coins needed and the remainder
# The remainder will "overwrite" the value previously held in the "money" variable
a, money = money // twopound, money % twopound # a = 1, money = 92
b, money = money // onepound, money % onepound # b = 0, money = 92
c, money = money // fiftyp, money % fiftyp # c = 1, money = 42
d, money = money // twentyp, money % twentyp # d = 2, money = 2
e, money = money // tenp, money % tenp # e = 0, money = 2
f, money = money // fivep, money % fivep # f = 0, money = 2
g, money = money // twop, money % twop # g = 1, money = 0
e, money = money // onep, money % onep # e = 0, money = 0
print(a,b,c,d,e,f,g,h)
This solution uses both integer division and remainder to perform the calculations.
Let's do it the right way: with a loop
Let's face it: the above code is verbose. There must be a better way... and there is! Use a loop.
Consider the algorithm: you repeat the steps jumping from one bin to the next and getting the number of coins you need and the remainder. This can be written in a loop.
So, let's add a list to our toolbox:
denominations = [200, 100, 50, 20, 10, 5, 2, 1]
And let's store the results of each step in a second list:
coins = [] # We'll use the '.append()' method to add elements to this list
So, starting in the first "bin":
n, money = money // denominations[0] , money % denominations[0]
coins.append(n)
Let's put this in a loop:
def select_coins_v2():
denominations = [200, 100, 50, 20, 10, 5, 2, 1]
coins = []
money = int(input('Enter how much money you have in pence'))
for i in range(len(denominations)):
n, money = money // denominations[i], money % denominations[i]
coins.append(n)
print(coins)
And that's it!
Another improvement: get the denomination only once and use it twice
Notice that the code above still has an issue: you read denominations twice. It would be nice if the denomination value could be read only once.
Of course, there is a way:
def select_coins_v3():
denominations = [200, 100, 50, 20, 10, 5, 2, 1]
coins = []
money = int(input('Enter how much money you have in pence'))
for d in denominations: # 'd' will hold the value of the denomination
n, money = money // d, money % d
coins.append(n)
print(coins)
As a friend of mine says: "Fast, precise and concise; not slow, difuse and confusing"
TL;DR
In Python 3.x, the "integer division" operator is // and the remainder (modulo) operator is %.
You can perform multiple assignement in a single line of code:
a, b = 1, 2
You can store the denominations in a list:
denominations = [200, 100, 50, 20, 10, 5, 2, 1]
You can read from the denominations list and get both the integer division and the remainder in a single step:
n, money = money // denominations[0], money % denominations[0]
You can write a loop that does all of the above:
for d in denominations: n, money = money // d, money % d
Bonus: Use a dictionary
What if I want to print both the denominations and the number of coins of each denomination I used? You can traverse both lists with a loop, but you can also keep it simple by using a dictionary:
def select_coins_v4():
denominations = [200, 100, 50, 20, 10, 5, 2, 1]
coins = []
money = int(input('Enter how much money you have in pence'))
for d in denominations: # 'd' will hold the value of the denomination
n, money = money // d, money % d
coins.append(n)
number_of_coins = dict(zip(denominations, coins))
print(number_of_coins)
Python offers a great deal of flexibility. Feel free to try different ways of getting what you need... and choose the easier one.
Hope this helps.
the cool thing about using real denominations is that the greedy solution will always find the optimal solution ... this stops holding true with weird denominations... but these problems are always easiest if you break them into parts
def get_one_change(amt_due):
# find how many of the largest denomination that you can use is
# ie for 60 = 1x50p is the count and number of largest
# for 4 = 4x1p ; 21 = 2x10p ; etc
return pence,count # ie 50,1 would be 1 50p coin
once you have this you just need to repeatedly call it and adjust your result until you have no change due
def get_change(amount_due):
changes_due = [] # to keep track
while amount_due:
pence,qty_of_coin = get_one_change(amount_due)
changes_due.append({"coin":pence,"qty":qty_of_coin})
amount_due = amount_due - (pence*qty_of_coin)
return changes_due
now you can just call your get_change method with your users input
I have created a program which simulates an entire football season between teams. The user inputs the teams' names and their skill ratings. It then uses the Poisson distribution to compare their skill ratings and calculate the result between the two teams. After each match, the relevant lists are updated: the winning teams gains 3 points (so if it is the third team that has won then the value at index [2] increases by 3). I have a separate list for points, goals scored, goals conceded, games won, games drawn, and games lost (side note - is there a more efficient way of doing this?)
The problem I have comes at the end of the season: each team is outputted with their data in the order that the teams were originally input. This is done using the fact that a team's name in the 'names' list is the same index as their points in the 'points' list. So the issue is, if I order the 'points' list then they will be out of sync with their names. I hope this makes sense but here is an example output for a season:
Enter number of teams in league: 4
Enter team 1 name: a
Enter team 2 name: b
Enter team 3 name: c
Enter team 4 name: d
Enter a skill: 1
Enter b skill: 3
Enter c skill: 5
Enter d skill: 8
===========================================
a's home games:
===========================================
a 2 - 0 b
a 0 - 2 c
a 0 - 0 d
===========================================
b's home games:
===========================================
b 2 - 3 a
b 1 - 0 c
b 0 - 0 d
===========================================
c's home games:
===========================================
c 1 - 0 a
c 1 - 0 b
c 0 - 1 d
===========================================
d's home games:
===========================================
d 4 - 0 a
d 2 - 0 b
d 0 - 0 c
Final table:
a Skill: 1 Points: 7 For: 5 Against: 9 Goal difference: -4 Wins: 2 Draws: 1 Losses: 3
b Skill: 3 Points: 4 For: 3 Against: 8 Goal difference: -5 Wins: 1 Draws: 1 Losses: 4
c Skill: 5 Points: 10 For: 4 Against: 2 Goal difference: 2 Wins: 3 Draws: 1 Losses: 2
d Skill: 8 Points: 12 For: 7 Against: 0 Goal difference: 7 Wins: 3 Draws: 3 Losses: 0
[4, 7, 10, 12]
So what I would now like to do is to be able to print a final league table in descending points order, rather than the way it prints now just in index order.
Sorry if this is poorly worded - the code for my program might be more useful so here it is:
import math
import random
#Lambda value in Poisson distribution for higher rated team
lambOne = 1.148698355
#Lambda value for lower rated team
lambTwo = 0.8705505633
#Poisson distribution calculating goals scored by the home team
def homeMatch(homeRating,awayRating):
global lambOne
global x
global y
if x == y:
raise ValueError
else:
lamb = lambOne**(int(homeRating)-int(awayRating))
homeScore = 0
z = random.random()
while z > 0:
z = z - ((lamb**homeScore * math.exp(lamb * -1))/(math.factorial(homeScore)))
homeScore += 1
return (homeScore-1)
#Poisson distribution calculating goals scored by away team
def awayMatch(homeRating,awayRating):
global lambTwo
global x
global y
#This check is to stop a team playing itself
if x == y:
raise ValueError
else:
lamb = lambTwo**(int(homeRating)-int(awayRating))
awayScore = 0
z = random.random()
while z > 0:
z = z - ((lamb**awayScore * math.exp(lamb * -1))/(math.factorial(awayScore)))
awayScore += 1
return (awayScore-1)
#Selecting number of teams in league
leagueSize = int(input("Enter number of teams in league: "))
#Initialising empty lists
teamNames = []
teamSkill = []
teamPoints = []
teamFor = []
teamAgainst = []
teamWins = []
teamDraws = []
teamLosses = []
#Populating lists with number of zeroes equal to the number of teams (one zero for each)
for x in range(leagueSize):
teamPoints += [0]
teamFor += [0]
teamAgainst += [0]
teamWins += [0]
teamDraws += [0]
teamLosses += [0]
#Entering names and skill ratings for each team
for i in range(leagueSize):
teamNames += [input("Enter team "+str(i+1)+" name: ")]
for j in range(leagueSize):
teamSkill += [input("Enter "+teamNames[j]+" skill: ")]
#Initialising variables
homeScore = 0
awayScore = 0
#The season begins - each team plays all of its home games in one go
for x in range(leagueSize):
#input("Press enter to continue ")
print("===========================================")
print(teamNames[x]+"'s home games: ")
print("===========================================\n")
for y in range(leagueSize):
error = 0
try:
homeScore = homeMatch(teamSkill[x],teamSkill[y])
#Skipping a game to stop a team playing itself
except ValueError:
pass
error += 1
try:
awayScore = awayMatch(teamSkill[x],teamSkill[y])
except ValueError:
pass
if error == 0:
#Updating lists
print(teamNames[x],homeScore,"-",awayScore,teamNames[y],"\n")
teamFor[x] += homeScore
teamFor[y] += awayScore
teamAgainst[x] += awayScore
teamAgainst[y] += homeScore
if homeScore > awayScore:
teamWins[x] += 1
teamLosses[y] += 1
teamPoints[x] += 3
elif homeScore == awayScore:
teamDraws[x] += 1
teamDraws[y] += 1
teamPoints[x] += 1
teamPoints[y] += 1
else:
teamWins[y] += 1
teamLosses[x] += 1
teamPoints[y] += 3
else:
pass
#Printing table (unsorted)
print("Final table: ")
for x in range(leagueSize):
#Lots of formatting
print(teamNames[x]+(15-len(teamNames[x]))*" "+" Skill: "+str(teamSkill[x])+(5-len(str(teamSkill[x])))*" "+" Points: "+str(teamPoints[x])+(5-len(str(teamPoints[x])))*" "+" For: "+str(teamFor[x])+(5-len(str(teamFor[x])))*" "+" Against: "+str(teamAgainst[x])+(5-len(str(teamPoints[x])))*" "+" Goal difference: "+str(teamFor[x]-teamAgainst[x])+(5-len(str(teamFor[x]-teamAgainst[x])))*" "+" Wins: "+str(teamWins[x])+(5-len(str(teamWins[x])))*" "+" Draws: "+str(teamDraws[x])+(5-len(str(teamDraws[x])))*" "+" Losses: "+str(teamLosses[x])+(5-len(str(teamLosses[x])))*" ")
teamPoints.sort()
print(teamPoints)
Sorry that this is very long and likely poorly worded and inefficient but I hope someone will be able to help me! Thank you very much :)
While your current approach is (barely) workable, it makes it very difficult to (for example) change the information you want to store about each team. You might consider defining a Team class instead, each instance of which stores all the information about a specific team.
class Team:
def __init__(self, name, skill):
self.name = name
self.skill = skill
self.points = self.goals_for = self.goals_against = \
self.wins = self.draws = self.losses = 0
This lets you create a new team object by passing a name and a skill level, in this way:
t1 = Team("Bradford City", 3)
t1 now has attributes name and skill with the given values, as well as a number of others (points, goals_for, and so on) whose values are all zero.
Then you can initialise the league quite easily:
league_size = 4
teams = []
for _ in range(league_size):
teams.append(Team(input("Name of team "+str(_)+": "),
int(input("Team "+str(_)+"'s skill level: ")))
Then to print the skill level of each team you can loop over the list:
for team in teams:
print(team.name, team.skill)
I hope this gives you some idea how your approach can be simplified. Your functions to play the matches can also take teams as arguments now, and modify the team objects directly according to the computed outcomes.
To get to the answer you want, once you have a list of teams you can print them out sorted by the number of points they hold quite easily:
for team in sorted(teams, key=lambda t: t.points):
print(team.name, team.skill, team.points, ...)
As far as I can see, none of your global declarations were necessary (if a name isn't defined locally Python will look for a global name to satisfy a reference). Besides which, inputs to a function should usually be passed as arguments, it's rather bad practice just to grab things from the environment!
I hope this is sufficient for you to rework your program to be more tractable. As a beginner I'd say you have done extremely well to get this far. The next steps are going to be exciting for you!
Added later: Your all-play-all could be easier to program as a result:
for home in teams:
for away in teams:
if home is away: # Teams don't play themselves
continue
play_match(home, away)
The play_match function would simulate the match and adjust each team's statistics. Of course you could simulate the away matches with another line reading
play_match(away, home)
though I'm not sure your algorithm is symmetrical for that.