From 9c95a292ea1d562a61a569f752954220ba6cbbc0 Mon Sep 17 00:00:00 2001 From: Mariano Spadaccini Date: Fri, 14 Jun 2024 09:13:08 +0200 Subject: Add ch-1 and ch-2 in Python --- challenge-273/spadacciniweb/python/ch-2.py | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 challenge-273/spadacciniweb/python/ch-2.py (limited to 'challenge-273/spadacciniweb/python/ch-2.py') 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) -- cgit