Computers and Technology

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))

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 14:00, uday50
Select the correct answer. a company is currently focusing on creating specific management goals for itself. which level of maturity is the company demonstrating under the sse_ccm framework? a. performed informally b. planned and tracked c. quantitatively controlled d. well-defined e. continuously improving
Answers: 2
image
Computers and Technology, 23.06.2019 15:20, manarhizam12
An ou structure in your domain has one ou per department, and all the computer and user accounts are in their respective ous. you have configured several gpos defining computer and user policies and linked the gpos to the domain. a group of managers in the marketing department need different policies that differ from those of the rest of the marketing department users and computers, but you don't want to change the top-level ou structure. which of the following gpo processing features are you most likely to use? a, block inheritance b, gpo enforcement c, wmi filtering d, loopback processing
Answers: 3
image
Computers and Technology, 23.06.2019 19:00, amayax77
Write a program that displays the following menu: geometry calculator 1. calculate the area of a circle 2. calculate the area of a rectangle 3. calculate the area of a triangle 4. quit enter your choice (1-4): if the user enters 1, the program should ask for the radius of the circle and then display its area. use the following formula: area = ď€(the square of r) use 3.14159 for ď€ and the radius of the circle for r. if the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle’s area. use the following formula: area = length * width if the user enters 3, the program should ask for the length of the triangle’s base and its height, and then display its area. use the following formula: area = base * height * .5 if the user enters 4, the program should end. input validation: display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. do not accept negative values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height. note: if the user enters an improper menu choice (1-4), the program prints "the valid choices are 1 through 4. run the program again and select one of those." if the user enters a negative radius, the program prints "the radius can not be less than zero." if the user enters a negative value for height or base, the program prints "only enter positive values for base and height."
Answers: 1
image
Computers and Technology, 23.06.2019 19:30, bbgirl8638
Of the following pieces of information in a document, for which would you most likely insert a mail merge field?
Answers: 3
Do you know the correct answer?
In this section, you will use a stack to implement a program that checks if a string is balanced. Us...

Questions in other subjects:

Konu
Mathematics, 26.01.2021 23:10
Konu
SAT, 26.01.2021 23:10
Konu
Mathematics, 26.01.2021 23:10