aboutsummaryrefslogtreecommitdiff
path: root/challenge-273/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2024-06-11 13:20:59 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2024-06-11 13:20:59 +0100
commitf18d8d36fd5ac5fbc0f1686fa737213cfb0c4cbd (patch)
treead974bf13ceadafa33de46f5690a52d9da8e5f01 /challenge-273/eric-cheung/python
parenta08549ab8d51fba7f19190abaf01ec59ba175307 (diff)
downloadperlweeklychallenge-club-f18d8d36fd5ac5fbc0f1686fa737213cfb0c4cbd.tar.gz
perlweeklychallenge-club-f18d8d36fd5ac5fbc0f1686fa737213cfb0c4cbd.tar.bz2
perlweeklychallenge-club-f18d8d36fd5ac5fbc0f1686fa737213cfb0c4cbd.zip
- Added solutions by Eric Cheung.
- Added solutions by Ulrich Rieke. - Added solutions by Wanderdoc. - Added solutions by Mark Anderson. - Added solutions by Peter Meszaros. - Added solutions by Niels van Dijke. - Added solutions by E. Choroba. - Added solutions by Peter Campbell Smith. - Added solutions by David Ferrone. - Added solutions by Luca Ferrari. - Added solutions by Thomas Kohler. - Added solutions by Dave Jacoby. - Added solutions by Robbie Hatley. - Added solutions by PokGoPun. - Added solutions by Roger Bell_West.
Diffstat (limited to 'challenge-273/eric-cheung/python')
-rwxr-xr-xchallenge-273/eric-cheung/python/ch-1.py31
-rwxr-xr-xchallenge-273/eric-cheung/python/ch-2.py15
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-273/eric-cheung/python/ch-1.py b/challenge-273/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..e01e8f5dca
--- /dev/null
+++ b/challenge-273/eric-cheung/python/ch-1.py
@@ -0,0 +1,31 @@
+
+def round(dInput):
+ return int(dInput) + (1 if dInput - int(dInput) >= 0.5 else 0)
+
+## Example 1
+strInput = "perl"
+strChar = "e"
+
+## Example 2
+## strInput = "java"
+## strChar = "a"
+
+## Example 3
+## strInput = "python"
+## strChar = "m"
+
+## Example 4
+## strInput = "ada"
+## strChar = "a"
+
+## Example 5
+## strInput = "ballerina"
+## strChar = "l"
+
+## Example 6
+## strInput = "analitik"
+## strChar = "k"
+
+nPercent = round(strInput.count(strChar) * 100 / len(strInput))
+
+print (nPercent)
diff --git a/challenge-273/eric-cheung/python/ch-2.py b/challenge-273/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..2b9c57d362
--- /dev/null
+++ b/challenge-273/eric-cheung/python/ch-2.py
@@ -0,0 +1,15 @@
+
+## strInput = "aabb" ## Example 1
+## strInput = "abab" ## Example 2
+## strInput = "aaa" ## Example 3
+strInput = "bbb" ## Example 4
+
+if strInput.count("b") <= 1:
+ print (False)
+else:
+ nFirstBPos = strInput.index("b")
+
+ nNumOfA = strInput[nFirstBPos + 1:].count("a")
+ nNumOfB = strInput[nFirstBPos + 1:].count("b")
+
+ print (nNumOfA == 0 and nNumOfB > 0)