livepython.net

266. Python Program to Run a Rock-Paper-Scissors Tournament

HardPhase 3 · Challenge

It takes a few steps, but you know every tool it uses: dictionaries, sort(), range() and split(). Score Example 1 on paper first.

Overview

Sports apps keep a league table: every result gives points, and the table shows who is on top. The same steps work for any game, from football to rock-paper-scissors.

Problem Statement

Aroha runs a rock-paper-scissors tournament at a school. Each line is one game: <player1> <move1> <player2> <move2>, like Ana rock Ben scissors. The last line is end. Games are numbered from 1.

The rules of the game:

  • Rock beats scissors.
  • Scissors beats paper.
  • Paper beats rock.
  • The same move on both sides is a draw.

The points:

  • A win gives the winner 3 points, and the loser 0.
  • A draw gives each player 1 point.

The moves must be rock, paper or scissors, in small letters. If either move is anything else, print Game <n> skipped: bad move. A skipped game counts as if it was never played: its players get no points, and they join the table only if they play a good game.

After end, print one line <name> <points> for each player, from the most points to the fewest. Players with the same points go in A to Z order. If no game was played, print No games.

Examples

Example 1. Input:

Ana rock Ben scissors
Ben paper Chen paper
Chen rock Ana paper
end

gives:

Ana 6
Ben 1
Chen 1

Why: Ana wins both games, so Ana has 3 + 3 = 6. Ben and Chen draw their game and get 1 point each. They tie, so Ben goes first.

Example 2. Input:

Zoe paper Max rock
Max rock Zoe stone
Max scissors Zoe paper
Lee rock Max rock
end

gives:

Game 2 skipped: bad move
Max 4
Zoe 3
Lee 1

Why: stone is not a move, so game 2 is skipped. Zoe wins game 1, Max wins game 3, and Max and Lee draw game 4. Max has 3 + 1 = 4.

Input

One game per line, then a last line end. Names are single words that start with a capital letter. A player never plays against themselves. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

One line for each skipped game, then the table, or No games. The tests try 7 different inputs, also a 3-way tie, a player with 0 points, a player who only plays in a skipped game, and the move Rock with a capital R.

Try it first. The solution opens when you solve this question, or after 3 tries with Submit.

Finish this chapter firstChapter 13 · Dictionaries
solution.py
# write your code here

EXPECTED OUTPUT

1Ana 6
2Ben 1
3Chen 1

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.