From acf41937fa2a87eb50b8534f2ca5c3d47ea858f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Doramas=20Garc=C3=ADa=20Jorge?= Date: Fri, 29 May 2026 15:00:40 +0100 Subject: [PATCH] Solve "Hello World" exercise --- README.md | 5 +-- python/hello-world/README.md | 45 ++++++++++++++++++++++++++ python/hello-world/hello_world.py | 2 ++ python/hello-world/hello_world_test.py | 30 +++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 python/hello-world/README.md create mode 100644 python/hello-world/hello_world.py create mode 100644 python/hello-world/hello_world_test.py diff --git a/README.md b/README.md index fce33a7..aaaea18 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,11 @@ Personal solutions to [**Python** track][python_track] exercises from [**Exercis ## Solutions +1. ["**Hello World**" solution](python\hello-world\hello_world.py). [python_version_badge]: https://img.shields.io/badge/Python%203.13-3776AB?logo=python&logoColor=FFD43B -[track_completion_badge]: https://img.shields.io/badge/Track%20completion-0.0%25-604fcd?logo=exercism&logoColor=604fcd&labelColor=e9ecef -[exercises_completed_badge]: https://img.shields.io/badge/Exercises%20completed-0%2F146-604fcd?logo=exercism&logoColor=604fcd&labelColor=e9ecef +[track_completion_badge]: https://img.shields.io/badge/Track%20completion-0.7%25-604fcd?logo=exercism&logoColor=604fcd&labelColor=e9ecef +[exercises_completed_badge]: https://img.shields.io/badge/Exercises%20completed-1%2F146-604fcd?logo=exercism&logoColor=604fcd&labelColor=e9ecef [python_track]: https://exercism.org/tracks/python [exercism]: https://exercism.org diff --git a/python/hello-world/README.md b/python/hello-world/README.md new file mode 100644 index 0000000..cae8c64 --- /dev/null +++ b/python/hello-world/README.md @@ -0,0 +1,45 @@ +# Hello World + +Welcome to Hello World on Exercism's Python Track. + +## Instructions + +The classical introductory exercise. +Just say "Hello, World!". + +["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment. + +The objectives are simple: + +- Modify the provided code so that it produces the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program + +## Source + +### Created by + +- @michaelem + +### Contributed to by + +- @behrtam +- @cmccandless +- @Dog +- @hebertjulio +- @ikhadykin +- @kytrinyx +- @N-Parsons +- @NobbZ +- @pheanex +- @skeskali +- @Sukhj1nder +- @tqa236 + +### Based on + +This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program \ No newline at end of file diff --git a/python/hello-world/hello_world.py b/python/hello-world/hello_world.py new file mode 100644 index 0000000..d695ea1 --- /dev/null +++ b/python/hello-world/hello_world.py @@ -0,0 +1,2 @@ +def hello(): + return 'Hello, World!' diff --git a/python/hello-world/hello_world_test.py b/python/hello-world/hello_world_test.py new file mode 100644 index 0000000..15473f5 --- /dev/null +++ b/python/hello-world/hello_world_test.py @@ -0,0 +1,30 @@ +# These tests are auto-generated with test data from: +# https://github.com/exercism/problem-specifications/tree/main/exercises/hello-world/canonical-data.json +# File last updated on 2023-07-19 + +import unittest + +try: + from hello_world import ( + hello, + ) + +except ImportError as import_fail: + message = import_fail.args[0].split("(", maxsplit=1) + item_name = import_fail.args[0].split()[3] + + item_name = item_name[:-1] + "()'" + + # pylint: disable=raise-missing-from + raise ImportError( + "\n\nMISSING FUNCTION --> In your 'hello_world.py' file, we can not find or import the" + f" function named {item_name}. \nThe tests for this first exercise expect a function that" + f' returns the string "Hello, World!"' + f'\n\nDid you use print("Hello, World!") instead?' + ) from None + + +class HelloWorldTest(unittest.TestCase): + def test_say_hi(self): + msg = "\n\nThis test expects a return of the string 'Hello, World!' \nDid you use print('Hello, World!') by mistake?" + self.assertEqual(hello(), "Hello, World!", msg=msg)