aboutsummaryrefslogtreecommitdiff
path: root/challenge-287/sgreen/python/ch-2.py
diff options
context:
space:
mode:
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()