From 96d41334bb415f1f019b539522b422df5e7c5eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20S=C3=A1nchez=20Escribano?= Date: Sun, 16 Jun 2024 17:41:23 +0200 Subject: [PATCH] reto 24 python cyberdidac --- Roadmap/24 - DECORADORES/python/cyberdidac.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Roadmap/24 - DECORADORES/python/cyberdidac.py diff --git a/Roadmap/24 - DECORADORES/python/cyberdidac.py b/Roadmap/24 - DECORADORES/python/cyberdidac.py new file mode 100644 index 0000000000..c5288a0180 --- /dev/null +++ b/Roadmap/24 - DECORADORES/python/cyberdidac.py @@ -0,0 +1,22 @@ +def count_calls(func): + def wrapper(): + wrapper.count += 1 + print(f"La funciĆ³n {func.__name__} ha sido llamada {wrapper.count} veces") + return func() + + wrapper.count = 0 + return wrapper + + +@count_calls +def say_hello(): + print("Hola!") + + +def main(): + say_hello() + say_hello() + + +if __name__ == '__main__': + main()