aboutsummaryrefslogtreecommitdiff
path: root/challenge-287/eric-cheung/python/ch-2.py
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2024-09-18 19:56:42 -0400
committerDave Jacoby <jacoby.david@gmail.com>2024-09-18 19:56:42 -0400
commitf86f5e2fec16020c1d86f9028fb0f61cfeac106e (patch)
tree0fd388a696b51ffde5a7bfe8519a74e1caf42461 /challenge-287/eric-cheung/python/ch-2.py
parentff8719c86653d5ad3121955e9494a0010527c2b9 (diff)
parent0052ec63ca70eaa6d9ffb1926c294dbfd85f8c05 (diff)
downloadperlweeklychallenge-club-f86f5e2fec16020c1d86f9028fb0f61cfeac106e.tar.gz
perlweeklychallenge-club-f86f5e2fec16020c1d86f9028fb0f61cfeac106e.tar.bz2
perlweeklychallenge-club-f86f5e2fec16020c1d86f9028fb0f61cfeac106e.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-287/eric-cheung/python/ch-2.py')
-rwxr-xr-xchallenge-287/eric-cheung/python/ch-2.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-287/eric-cheung/python/ch-2.py b/challenge-287/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..ede897bb14
--- /dev/null
+++ b/challenge-287/eric-cheung/python/ch-2.py
@@ -0,0 +1,45 @@
+
+def IsValidDef (strFunc, bAllowDecimal):
+ if not bAllowDecimal and "." in strFunc:
+ return False
+
+ if strFunc == ".":
+ return False
+
+ if (strFunc[0] in ["+", "-"]):
+ strFunc = strFunc[1:]
+
+ arrPart = strFunc.split(".")
+
+ if len(arrPart) > 2:
+ return False
+
+ for strLoop in arrPart:
+ if not strLoop:
+ continue
+ if not strLoop.isnumeric():
+ return False
+
+ return True
+
+def IsValidNum (strFunc):
+ arrPart = strFunc.lower().split("e")
+
+ if len(arrPart) > 2:
+ return False
+
+ for nIndx, strLoop in enumerate(arrPart):
+ if not IsValidDef (strLoop, nIndx == 0):
+ return False
+
+ return True
+
+## strInput = "1" ## Example 1
+## strInput = "a" ## Example 2
+## strInput = "." ## Example 3
+## strInput = "1.2e4.2" ## Example 4
+## strInput = "-1." ## Example 5
+## strInput = "+1E-8" ## Example 6
+strInput = ".44" ## Example 7
+
+print (IsValidNum(strInput))