subject

In this section, you will use a stack to implement a program that checks if a string is balanced. Use the skeleton code provided below to accept inputs via command line arguments. Do not modify how the inputs are accepted as this is how we will test your code. Be sure you handle a NULL input string; you can either consider a NULL string as balanced or ensure that the input string cannot be empty. You are to fill in the missing code for is_balanced() which must be implemented with a stack (no counter integers or string functions are allowed). If you use a counter or string operation of any kind, you will not receive credit for completing this part of the assignment. You may use Python's implementation of a list and you may add additional functions as you see fit. you may add additional functions as you see fit.

For running the code use: python balance. py "{}"

Skeleton code:

import sys

# Checks whether the input string is balanced
# param: input string
# returns True if string is balanced, otherwise returns False
def is_balanced(input_string):

# initialize an empty list as the stack
stack = []

# iterate over each character in the string
for i in input_string:

# FIXME: You will write this function

return False

if __name__ == '__main__':
# get input string
_input_string = sys. argv[1] # DO NOT MODIFY

balanced = is_balanced(_input_string)

if balanced:
print("The string {} is balanced".format(_input_string))
else:
print("The string {} is not balanced".format(_input_string))

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:40
Gabe wants to move text from one document to another document. he should copy the text, paste the text, and open the new document highlight the text, select the cut command, move to the new document, make sure the cursor is in the correct location, and select the paste command select the save as command, navigate to the new document, and click save highlight the text, open the new document, and press ctrl and v
Answers: 1
question
Computers and Technology, 22.06.2019 21:50
Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. thus your code should put 11 + 22 + 33 + + 4949 + 50*50 into total. use no variables other than k and total.
Answers: 2
question
Computers and Technology, 23.06.2019 21:00
Uget brainliest if accurate mary has been given the responsibility of hiring a person for the position of a software testing officer. which management function would mary achieve this responsibility?
Answers: 1
question
Computers and Technology, 23.06.2019 23:40
4. what is the reason for including the following code snippet in the header file animal.h? #ifndef animal_h #define animal_h class animal { public: animal(); animal(double new_area_hunt); void birth(); void hunt(double new_area_hunt); void death(); double get_area_hunt() const; private: double area_hunt; }; #endif
Answers: 3
You know the right answer?
In this section, you will use a stack to implement a program that checks if a string is balanced. Us...
Questions
question
Biology, 23.04.2020 16:19
question
Mathematics, 23.04.2020 16:19
question
History, 23.04.2020 16:19
question
Mathematics, 23.04.2020 16:19
question
Mathematics, 23.04.2020 16:19
question
Biology, 23.04.2020 16:19