Python Forum

Full Version: Python program that list all possible football outcome combinations
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear all, I would like to learn Python by working on a project. The project is to write Python code that can print out a list of all possible football outcome combinations for 8 matches, where each match has 3 possible outcomes (1=home team win, 2=away team win, X=draw). How can I go about this?
Thank you very much!
(Jul-18-2017, 09:35 AM)lukorir Wrote: [ -> ]Dear all, I would like to learn Python by working on a project. The project is to write Python code that can print out a list of all possible football outcome combinations for 8 matches, where each match has 3 possible outcomes (1=home team win, 2=away team win, X=draw). How can I go about this?

Here is the code

# Input this part then enter number of matches
import random
n=int(input("Enter number of games: "))

# After entering number of matches, write the following:
p=3**n
for x in range(p):
print( ''.join(random.choice('1X2') for _ in range(n)))

# Someone can add to this code part for removal of duplicates
Try from itertools product, combinations, combinations_with_replacement and permutations.

import itertools


outcomes = (0, 1, 2)
teams = 8
team_outcomes = [outcomes] * teams
iterator = itertools.product(*team_outcomes)
possible_solutions = list(iterator)
6561 possible solutions. You can calculate this:
3**8
I wrote a very simple football predictor with GUI.
I'm afraid it is not very well written at all,
but it may give you some ideas. Source code here:
https://stevepython.wordpress.com/2019/0...pdate-v0-8