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, 24.06.2019 05:50
What all vehicles has tesla inc. created over the years
Answers: 3
question
Computers and Technology, 24.06.2019 08:00
Arah has entered data about football players from team a and team b in a worksheet. she enters names of players from team a with details about each player in different columns of the worksheet. similarly, she enters details of all the players from team b. which option will her view the data for team a and team b in two separate sections after printing? a. page break view b. freeze pane view c. split screen view d. full screen view e. zoom out view
Answers: 1
question
Computers and Technology, 24.06.2019 16:50
Ideally, the backrest is tilted back slightly, so when you turn the wheel your shoulders are the seat.
Answers: 2
question
Computers and Technology, 24.06.2019 17:30
Click on the tab on the ribbon to open the backstage view. file view insert review
Answers: 1
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
Advanced Placement (AP), 26.08.2019 02:30
question
Law, 26.08.2019 02:30
question
Mathematics, 26.08.2019 02:30
question
Physics, 26.08.2019 02:30