aboutsummaryrefslogtreecommitdiff
path: root/challenge-273/spadacciniweb/python/ch-2.py
diff options
context:
space:
mode:
authorATSchneider <atschneider@temple.edu>2024-06-16 07:37:39 -0400
committerGitHub <noreply@github.com>2024-06-16 07:37:39 -0400
commitbd67c7d68d54058bc6bc6b41ae8bbc8de725314f (patch)
treeb19053d19cd2c6952b1677e099c20e03ca63f19d /challenge-273/spadacciniweb/python/ch-2.py
parent86f02124512baeea87ccccea67dc73bab9db71ca (diff)
parente7c6e4694cbc20e39268624c74ec9d5134bd66b7 (diff)
downloadperlweeklychallenge-club-bd67c7d68d54058bc6bc6b41ae8bbc8de725314f.tar.gz
perlweeklychallenge-club-bd67c7d68d54058bc6bc6b41ae8bbc8de725314f.tar.bz2
perlweeklychallenge-club-bd67c7d68d54058bc6bc6b41ae8bbc8de725314f.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-273/spadacciniweb/python/ch-2.py')
-rw-r--r--challenge-273/spadacciniweb/python/ch-2.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/challenge-273/spadacciniweb/python/ch-2.py b/challenge-273/spadacciniweb/python/ch-2.py
new file mode 100644
index 0000000000..dce0bca454
--- /dev/null
+++ b/challenge-273/spadacciniweb/python/ch-2.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl
+
+# Task 2: B After A
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given a string, $str.
+# Write a script to return true if there is at least one b, and no a appears after the first b.
+#
+# Example 1
+# Input: $str = "aabb"
+# Output: true
+#
+# Example 2
+# Input: $str = "abab"
+# Output: false
+#
+# Example 3
+# Input: $str = "aaa"
+# Output: false
+#
+# Example 4
+# Input: $str = "bbb"
+# Output: true
+
+def out(str):
+ offset = str.find('b')
+ if offset >= 0 and str.find('a', offset) == -1:
+ res = "true"
+ else:
+ res = "false"
+ print("%s -> %s" %
+ ( str, res )
+ )
+
+if __name__ == "__main__":
+ str = "aabb"
+ out(str)
+
+ str = "abab"
+ out(str)
+
+ str = "aaa"
+ out(str)
+
+ str = "bbb"
+ out(str)