Python program that list all possible football outcome combinations - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python program that list all possible football outcome combinations (/thread-4031.html) |
Python program that list all possible football outcome combinations - lukorir - Jul-18-2017 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? RE: Python program that list all possible football outcome combinations - buran - Jul-18-2017 check itertools.product https://docs.python.org/3/library/itertools.html#itertools.product RE: Python program that list all possible football outcome combinations - lukorir - Sep-29-2017 Thank you very much! RE: Python program that list all possible football outcome combinations - RKO - Oct-08-2019 (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 RE: Python program that list all possible football outcome combinations - DeaD_EyE - Oct-08-2019 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
RE: Python program that list all possible football outcome combinations - steve_shambles - Oct-17-2019 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/08/14/footy-predictor-update-v0-8 |