Python Forum
Python program that list all possible football outcome combinations
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python program that list all possible football outcome combinations
#1
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?
Reply
#2
check itertools.product

https://docs.python.org/3/library/iterto...ls.product
Reply
#3
Thank you very much!
Reply
#4
(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
Reply
#5
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
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#6
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Program to find Mode of a list PythonBoy 6 996 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  Finding combinations of list of items (30 or so) LynnS 1 836 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  Python Program to Find the Total Sum of a Nested List vlearner 8 4,782 Jan-23-2022, 07:20 PM
Last Post: menator01
  How can I find all combinations with a regular expression? AlekseyPython 0 1,636 Jun-23-2021, 04:48 PM
Last Post: AlekseyPython
  All possible combinations CODEP 2 1,826 Dec-01-2020, 06:10 PM
Last Post: deanhystad
  Triplet Combinations of All Values quest 2 1,937 Nov-05-2020, 09:22 AM
Last Post: quest
  outcome 0 but impossiblenumbers change bntayfur 1 1,451 Jul-05-2020, 09:05 PM
Last Post: Yoriz
  Not the expected outcome christopher3786 1 1,512 Jun-23-2020, 07:16 AM
Last Post: bowlofred
  All possible combinations of multiplications Shreya10o 0 1,632 May-23-2020, 07:45 AM
Last Post: Shreya10o
  Create a program that PING a list of IPs skaailet 7 6,121 Mar-26-2020, 10:46 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020