exercism

Exercism solutions.
Log | Files | Refs

commit b7d781c3caceaa462e620aded11e8867f6d1ab5d
parent 3b61491cbb55a2b43bdd9b0e156e982f2e711a7e
Author: dwrz <dwrz@dwrz.net>
Date:   Mon, 15 Nov 2021 20:53:01 +0000

Add python/high-scores

Diffstat:
Apython/high-scores/HELP.md | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apython/high-scores/README.md | 38++++++++++++++++++++++++++++++++++++++
Apython/high-scores/__pycache__/high_scores.cpython-39.pyc | 0
Apython/high-scores/__pycache__/high_scores_test.cpython-39-pytest-6.2.5.pyc | 0
Apython/high-scores/high_scores.py | 14++++++++++++++
Apython/high-scores/high_scores_test.py | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 166 insertions(+), 0 deletions(-)

diff --git a/python/high-scores/HELP.md b/python/high-scores/HELP.md @@ -0,0 +1,55 @@ +# Help + +## Running the tests + +To run the included *tests*, run the test file using the `pytest` module, replacing `{exercise_name}`: + +```bash +$ python3 -m pytest {exercise_name}_test.py +``` + +Many IDE's and code editors have built-in support for using Pytest to run tests; check them out [here](https://github.com/exercism/python/blob/main/docs/TOOLS.md#editors-and-ides). + +For more information about running tests using `pytest`, checkout our [Python testing guide](https://github.com/exercism/python/blob/main/docs/TESTS.md#pytest). + +### Common pytest options + +- `-v` : enable verbose output. +- `-x` : stop running tests on first failure. +- `--ff` : run failures from previous test before running other test cases. + +For other options, see `python3 -m pytest -h`. + +## Submitting your solution + +You can submit your solution using the `exercism submit high_scores.py` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Python track's documentation](https://exercism.org/docs/tracks/python) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +Below are some resources for getting help if you run into trouble: + +- [The PSF](https://www.python.org) hosts Python downloads, documentation, and community resources. +- [Python Community on Discord](https://pythondiscord.com/) is a very helpful and active community. +- [#python on Libera.chat](https://www.python.org/community/irc/) this is where the cored developers for the language hang out and get work done. +- [Exercism on Gitter](https://gitter.im/exercism/home) join the Python room for Python-related questions or problems. +- [/r/learnpython/](https://www.reddit.com/r/learnpython/) is a subreddit designed for Python learners. +- [Python Community Forums](https://discuss.python.org/) +- [Pythontutor](http://pythontutor.com/) for stepping through small code snippets visually. + + +Additionally, [StackOverflow](http://stackoverflow.com/questions/tagged/python) is a good spot to search for your problem/question to see if it has been answered already. + If not - you can always [ask](https://stackoverflow.com/help/how-to-ask) or [answer](https://stackoverflow.com/help/how-to-answer) someone else's question. +\ No newline at end of file diff --git a/python/high-scores/README.md b/python/high-scores/README.md @@ -0,0 +1,37 @@ +# High Scores + +Welcome to High Scores on Exercism's Python Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Manage a game player's High Score list. + +Your task is to build a high-score component of the classic Frogger game, one of the highest selling and addictive games of all time, and a classic of the arcade era. Your task is to write methods that return the highest score from the list, the last added score and the three highest scores. + +In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find yourself using them again and again in problems both simple and complex. + +- [**Data Structures (Python 3 Documentation Tutorial)**](https://docs.python.org/3/tutorial/datastructures.html) +- [**Lists and Tuples in Python (Real Python)**](https://realpython.com/python-lists-tuples/) +- [**Python Lists (Google for Education)**](https://developers.google.com/edu/python/lists) + +## Source + +### Created by + +- @behrtam + +### Contributed to by + +- @BethanyG +- @cmccandless +- @Dog +- @gabriel376 +- @GascaK +- @simmol +- @tqa236 +- @yawpitch + +### Based on + +Tribute to the eighties' arcade game Frogger +\ No newline at end of file diff --git a/python/high-scores/__pycache__/high_scores.cpython-39.pyc b/python/high-scores/__pycache__/high_scores.cpython-39.pyc Binary files differ. diff --git a/python/high-scores/__pycache__/high_scores_test.cpython-39-pytest-6.2.5.pyc b/python/high-scores/__pycache__/high_scores_test.cpython-39-pytest-6.2.5.pyc Binary files differ. diff --git a/python/high-scores/high_scores.py b/python/high-scores/high_scores.py @@ -0,0 +1,14 @@ +def latest(scores): + return scores[-1] + +def personal_best(scores): + return max(scores) + +def personal_top_three(scores): + return sorted(scores, reverse=True)[:3] + +def latest_after_top_three(scores): + return latest(scores) + +def scores_after_top_three(scores): + return scores diff --git a/python/high-scores/high_scores_test.py b/python/high-scores/high_scores_test.py @@ -0,0 +1,58 @@ +import unittest + +from high_scores import ( + latest, + latest_after_top_three, + personal_best, + personal_top_three, + scores_after_top_three, +) + +# Tests adapted from `problem-specifications//canonical-data.json` + + +class HighScoresTest(unittest.TestCase): + def test_latest_score(self): + scores = [100, 0, 90, 30] + expected = 30 + self.assertEqual(latest(scores), expected) + + def test_personal_best(self): + scores = [40, 100, 70] + expected = 100 + self.assertEqual(personal_best(scores), expected) + + def test_personal_top_three_from_a_list_of_scores(self): + scores = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70] + expected = [100, 90, 70] + self.assertEqual(personal_top_three(scores), expected) + + def test_personal_top_highest_to_lowest(self): + scores = [20, 10, 30] + expected = [30, 20, 10] + self.assertEqual(personal_top_three(scores), expected) + + def test_personal_top_when_there_is_a_tie(self): + scores = [40, 20, 40, 30] + expected = [40, 40, 30] + self.assertEqual(personal_top_three(scores), expected) + + def test_personal_top_when_there_are_less_than_3(self): + scores = [30, 70] + expected = [70, 30] + self.assertEqual(personal_top_three(scores), expected) + + def test_personal_top_when_there_is_only_one(self): + scores = [40] + expected = [40] + self.assertEqual(personal_top_three(scores), expected) + + def test_latest_score_after_personal_top_scores(self): + scores = [70, 50, 20, 30] + expected = 30 + self.assertEqual(latest_after_top_three(scores), expected) + + def test_scores_after_personal_top_scores(self): + scores = [30, 50, 20, 70] + expected = [30, 50, 20, 70] + self.assertEqual(scores_after_top_three(scores), expected)