diff --git a/Basic-Scripts/balanced_paranthesis.py b/Basic-Scripts/balanced_paranthesis.py new file mode 100644 index 00000000..7709f1b8 --- /dev/null +++ b/Basic-Scripts/balanced_paranthesis.py @@ -0,0 +1,40 @@ +openBracketList = ["[", "{", "("] +closeBracketList = ["]", "}", ")"] + + +def check_parentheses(data: str) -> str: + """ + check_parentheses() : Will take a string as an arguement and each time when an open parentheses is encountered + will push it in the stack, and when closed parenthesis is encountered, + will match it with the top of stack and pop it. + + Parameters: + data (str): takes a string. + + Returns: + str: Returns a string value whether string passed is balanced or Unbalanced. + """ + stack = [] + for index in data: + if index in openBracketList: + stack.append(index) + elif index in closeBracketList: + position = closeBracketList.index(index) + if (len(stack) > 0) and ( + openBracketList[position] == stack[len(stack) - 1] + ): + stack.pop() + else: + return "Unbalanced" + if len(stack) == 0: + return "Balanced" + else: + return "Unbalanced" + + +if __name__ == "__main__": + + data = input("Enter the string to check:\t") + result = check_parentheses(data) + print(result) + diff --git a/Contribution.md b/Contribution.md index 435f436f..b95e8f05 100644 --- a/Contribution.md +++ b/Contribution.md @@ -2,16 +2,28 @@ If this is your first time to open source contribution in python So that I have created this repo for all the you to start contributing. # How to contribute! - ## Steps: - * fork the [repository](https://github.com/ankitdobhal/Python-Scripts) - * Clone the fork [repo](https://github.com/ankitdobhal/Python-Scripts) - (git clone https://github.com/ankitdobhal/Python-Scripts) - * Create new branch - (git checkout -b ) - * Add files in scripts folder - (git add ) - * Add a commit message ! - (git commit -a -m "") - * Push changes - (git push origin) - * Create pull requests + +## Steps: + - First commment on the issue in which you want to work upon. + - Issue-1 : https://github.com/ankitdobhal/Awesome-Python-Scripts/issues/91 + - Issue-2 : https://github.com/ankitdobhal/Awesome-Python-Scripts/issues/92 + - Issue-3 : https://github.com/ankitdobhal/Awesome-Python-Scripts/issues/93 + - Issue-4 : https://github.com/ankitdobhal/Awesome-Python-Scripts/issues/94 + + - Fork the [repository](https://github.com/ankitdobhal/Awesome-Python-Scripts) + + - Clone the fork [repo](https://github.com/ankitdobhal/Awesome-Python-Scripts) + - git clone https://github.com/ankitdobhal/Awesome-Python-Scripts + - Create new branch + - git checkout -b + + - Add Scripts related to your respective issues. + - git add + + - Add a commit message ! + - git commit -a -m "" + - Push changes + - git push origin + + - Create pull requests + - [Try to Mention the related issue for your PR]