diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-17 10:23:54 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-17 10:23:54 +0100 |
| commit | 8c709f314b9ff11568342684891c466aab170bdd (patch) | |
| tree | effec6e796c6781f8915836894f551dc5f71773c /challenge-287/eric-cheung/python/ch-2.py | |
| parent | 3faccf43af8f3a2c7df4e9bab6f49994336e8b11 (diff) | |
| download | perlweeklychallenge-club-8c709f314b9ff11568342684891c466aab170bdd.tar.gz perlweeklychallenge-club-8c709f314b9ff11568342684891c466aab170bdd.tar.bz2 perlweeklychallenge-club-8c709f314b9ff11568342684891c466aab170bdd.zip | |
- Added solutions by PokGoPun.
- Added solutions by Eric Cheung.
- Added solutions by Conor Hoekstra.
Diffstat (limited to 'challenge-287/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-287/eric-cheung/python/ch-2.py | 45 |
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))
|
