asked 69.3k views
1 vote
Python Program Help!

Last century, the AFL had 12 teams, and at the end of the
regular (home-and-away) season, a series of Finals games were
played to decide the winner of the football premiership for

1 Answer

4 votes

Answer:

Python Program Help!

Last century, the AFL had 12 teams, and at the end of the regular (home-and-away) season, a series of Finals games were played to decide the winner of the football premiership for that year. Up to 1971, the Finals Series involved four teams, who played in 4 Finals games:

Game 1: (The First Semi-Final): Team 3 plays Team 4. The loser drops out, the winner goes into Game 3

Game 2: (The Second Semi-Final): Team 1 plays Team 2. The winner goes into Game 4. The loser goes into Game 3.

Game 3: (The Preliminary Final): The winner from Game 1 plays the loser from Game 2. The loser drops out and the winner goes into Game 4.

Game 4: (The Grand Final): The winner of Game 2 plays the winner of Game 3. The winner of the Grand Final wins the Premiership!

The 12 teams were:

AFL Teams

Carlton

Collingwood

Essendon

Fitzroy

Footscray

Geelong

Hawthorn

Melbourne

North Melbourne

Richmond

St Kilda

South Melbourne

Task:

Write a Python program to do the following:

1. Take as the input a Python string made up of any four of the 12 teams, in the order they finished the regular season. The input string should separate the teams with commas and should not have any white space between the teams, e.g "Melbourne, Carlton, Geelong, St Kilda".

2. Test whether the input contains exactly four teams, and all teams are in the AFL. Print an error message if the input is not suitable.

3. Print out the winner and loser of each game.

The winner of each finals game should be the team whose name has the larger ASCII sum. This is equal to the sum of the ASCII ordinal numbers of each letter in the team's name. For teams whose name is made up of two words, do not count the space character. If two teams have the same ASCII sum, the first team is declared the winner.

Example:

Which teams are playing in the finals this year? Melbourne, Carlton, Geelong, St Kilda

Geelong defeated St Kilda in the First Semi-Final.

Melbourne defeated Carlton in the Second Semi-Final

Carlton defeated Geelong in the Preliminary Final.

Melbourne defeated Carlton in the Grand Final.

Melbourne win the Premiership!

You need to handle duplicate teams in the input, as well as teams not in the AFL_TEAMS:

Which teams are playing in the finals this year? Melbourne, Carlton, Geelong, Melbourne

answered
User Sharad Kale
by
7.9k points