aboutsummaryrefslogtreecommitdiff
path: root/challenge-160/lubos-kolouch/python/ch-1.py
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2022-04-15 12:51:48 +0200
committerLubos Kolouch <lubos@kolouch.net>2022-04-15 12:51:48 +0200
commit46d77034060ceade2fa2700a28ae3063d075f5a8 (patch)
tree4c17e7b0cd9346ee98684705c03c0998aacf373d /challenge-160/lubos-kolouch/python/ch-1.py
parent7d5f1e74fd301dddf5f943af26e00dc0a93350e8 (diff)
downloadperlweeklychallenge-club-46d77034060ceade2fa2700a28ae3063d075f5a8.tar.gz
perlweeklychallenge-club-46d77034060ceade2fa2700a28ae3063d075f5a8.tar.bz2
perlweeklychallenge-club-46d77034060ceade2fa2700a28ae3063d075f5a8.zip
feat(challenge-160/lubos-kolouch/p[erl,ython]/ch-[12].p[ly]): Challenge 160 Task 1 2 LK Perl Python
Diffstat (limited to 'challenge-160/lubos-kolouch/python/ch-1.py')
-rw-r--r--challenge-160/lubos-kolouch/python/ch-1.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-160/lubos-kolouch/python/ch-1.py b/challenge-160/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..9103fe6c84
--- /dev/null
+++ b/challenge-160/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,27 @@
+""" Challenge 160 Task 1"""
+
+from num2words import num2words
+
+
+def four_magic(what: int) -> str:
+ """Do the conversion magic"""
+
+ output = []
+
+ while 1:
+ new_num = len(num2words(what))
+
+ if what == 4:
+ output.append(num2words(what) + " is magic.")
+ break
+ output.append(num2words(what) + " is " + num2words(new_num))
+ what = new_num
+
+ out_str = ", ".join(output)
+
+ return out_str.capitalize()
+
+
+assert four_magic(5) == "Five is four, four is magic."
+assert four_magic(7) == "Seven is five, five is four, four is magic."
+assert four_magic(6) == "Six is three, three is five, five is four, four is magic."