aboutsummaryrefslogtreecommitdiff
path: root/challenge-287/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2024-09-22 17:27:47 +1000
committerSimon Green <mail@simon.green>2024-09-22 17:27:47 +1000
commit9e99d7529d22b326148431954541f6ffdd76497f (patch)
treedc71892d439a9be723f4ae8ef394d12d7a55daaf /challenge-287/sgreen/python/ch-2.py
parent68e321dd32a834f54b55d5e8924f04358e41cf1f (diff)
downloadperlweeklychallenge-club-9e99d7529d22b326148431954541f6ffdd76497f.tar.gz
perlweeklychallenge-club-9e99d7529d22b326148431954541f6ffdd76497f.tar.bz2
perlweeklychallenge-club-9e99d7529d22b326148431954541f6ffdd76497f.zip
sgreen solutions to challenge 287
Diffstat (limited to 'challenge-287/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-287/sgreen/python/ch-2.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-287/sgreen/python/ch-2.py b/challenge-287/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..87059a0873
--- /dev/null
+++ b/challenge-287/sgreen/python/ch-2.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+
+
+def valid_number(s: str) -> bool:
+ """Check if the given string is a valid number.
+
+ Args:
+ s (str): The supplied string.
+
+ Returns:
+ bool: True if the string is a valid number, False otherwise.
+ """
+ return bool(re.search(r'^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?$', s))
+
+
+def main():
+ result = valid_number(sys.argv[1])
+ print('true' if result else 'false')
+
+
+if __name__ == '__main__':
+ main()