diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2022-04-28 14:30:31 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2022-04-28 14:30:31 +0100 |
| commit | a75abacc4002f65777f6780026f7fab609aa14cd (patch) | |
| tree | accd7f49e2f2b898caf9686134db154917145283 | |
| parent | f1210b445c4b4124ee1247820be36550fe89517c (diff) | |
| download | perlweeklychallenge-club-a75abacc4002f65777f6780026f7fab609aa14cd.tar.gz perlweeklychallenge-club-a75abacc4002f65777f6780026f7fab609aa14cd.tar.bz2 perlweeklychallenge-club-a75abacc4002f65777f6780026f7fab609aa14cd.zip | |
Add Python solution to challenge 042
| -rw-r--r-- | challenge-042/paulo-custodio/python/ch-1.py | 23 | ||||
| -rw-r--r-- | challenge-042/paulo-custodio/python/ch-2.py | 30 |
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-042/paulo-custodio/python/ch-1.py b/challenge-042/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..8bd0e8d733 --- /dev/null +++ b/challenge-042/paulo-custodio/python/ch-1.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +# Challenge 042 +# +# TASK #1 +# Octal Number System +# Write a script to print decimal number 0 to 50 in Octal Number System. +# +# For example: +# +# Decimal 0 = Octal 0 +# Decimal 1 = Octal 1 +# Decimal 2 = Octal 2 +# Decimal 3 = Octal 3 +# Decimal 4 = Octal 4 +# Decimal 5 = Octal 5 +# Decimal 6 = Octal 6 +# Decimal 7 = Octal 7 +# Decimal 8 = Octal 10 +# and so on. + +for n in range(50+1): + print("Decimal", n, "= Octal", oct(n)[2:]) diff --git a/challenge-042/paulo-custodio/python/ch-2.py b/challenge-042/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..30ca5ee826 --- /dev/null +++ b/challenge-042/paulo-custodio/python/ch-2.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +# Challenge 042 +# +# TASK #2 +# Balanced Brackets +# Write a script to generate a string with random number of ( and ) brackets. +# Then make the script validate the string if it has balanced brackets. +# +# For example: +# +# () - OK +# (()) - OK +# )( - NOT OK +# ())() - NOT OK + +import fileinput +import re + +for line in fileinput.input(): + str = line.rstrip() + print(f"{str} - ", end="") + while True: + str, n = re.subn(r"\(\)", "", str) + if n==0: + break + if str=="": + print("OK") + else: + print("NOT OK") |
