Skip to content

Commit

Permalink
Merge pull request #2 from GopakumarRajappan/feature-1
Browse files Browse the repository at this point in the history
Updated the logic for early exit. Added missing condition for input
  • Loading branch information
GopakumarRajappan authored Dec 14, 2023
2 parents 8928b7c + b42a08e commit 4d53567
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions identify_parenthesis_pattern.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
def check_pattern(input_pattern):
## First check if the count of '(' and ')' are same. If not, return False.
count_opening_braces = 0
count_closing_braces = 0
for char in input_pattern:
if char == '(':
count_opening_braces += 1
if char == ')':
count_closing_braces += 1
# count_opening_braces = 0
# count_closing_braces = 0
# for char in input_pattern:
# if char == '(':
# count_opening_braces += 1
# if char == ')':
# count_closing_braces += 1

if count_opening_braces != count_closing_braces:
# if count_opening_braces != count_closing_braces:
# print("unequal number of open and closing braces in the pattern detected")
# return False
if len(input_pattern) % 2 != 0:
print("unequal number of open and closing braces in the pattern detected")
return False
else:
Expand Down Expand Up @@ -50,11 +53,14 @@ def check_pattern(input_pattern):
# Inorder for the Github action to succed, Hardcoding the input with an example value.
# Code verified with user prompted input already.
#input_pattern = input("Enter the string pattern: ").strip()
input_pattern = "()()()()"
for char in input_pattern:
if char not in ('(', ')'):
raise ValueError("Only '(' and ')' allowed in the input pattern")
checked_result = check_pattern(input_pattern)
print(checked_result)
input_pattern = "()()()"
if input_pattern:
for char in input_pattern:
if char not in ('(', ')'):
raise ValueError("Only '(' and ')' allowed in the input pattern")
checked_result = check_pattern(input_pattern)
print(checked_result)
else:
raise ValueError("Only '(' and ')' allowed in the input pattern")
except ValueError as e:
print(f"{e.args[0]}")

0 comments on commit 4d53567

Please sign in to comment.