Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

The Players

Time for another project! This checkpoint puts the last four lessons to work, Working with Text, Tuples and Sets, Sorting and List Comprehensions, together with everything you learned before them. As in the checkpoints before, the instructions say what the program should print, and how you write it is up to you. Each exercise continues where the previous one ended, with a finished program from the previous step in the editor, which may look different from yours.

The project. A small online game saves the result of every finished game. Over three exercises, your program will turn these results into a leaderboard: who has played, each player's best score from the highest down, the average score and who is above it.

The data. The variable games is a list of texts, one for each finished game. Each text is the player's name, a colon and the score, such as "eva:140". The players typed their names themselves, and it shows: Eva is "eva" one time and "Eva" the next, Tom is also "TOM", and Anna once typed spaces around her name. They're still only four players. A name counts in its cleaned-up form: without the spaces around it, with a capital first letter and the rest in lowercase. So " anna " is Anna.

The task. For these games, the program prints:

Games: 7
Total points: 740
Players: Anna, Eva, Max, Tom

The total points are the scores of all the games added up. Each player is listed once, in alphabetical order, with a comma and a space between the names.

A tip: .split(":") splits a game into the name and the score, and both are texts: " anna :120".split(":") is [' anna ', '120']. Turn the score into a number with int() before you add it up; otherwise the program ends with TypeError: unsupported operand type(s) for +=: 'int' and 'str'. Strip the spaces before you change the case: " anna ".capitalize() stays ' anna ', because its first character is a space. And a set keeps each name only once, but it has no order, so sort it before you print it.

Each exercise also runs your program with other data, for example with another score or an extra game, so it has to work everything out from the list. Try that yourself too, and then put the list back as it was: the exercise needs its lines.

Instructions

  1. 1

    Print the number of games and the total points.

  2. 2

    Below that, print the players: each one once, cleaned up, in alphabetical order.

Back

1/3

  1. 1. The Players
  2. 2. The Best Scores
  3. 3. Above Average
Next

Try it yourself

Do this exercise right here in your browser. No account needed.