1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alina [70]
3 years ago
5

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

Computers and Technology
1 answer:
zimovet [89]3 years ago
6 0

Answer:

Check the explanation

Explanation:

#source code:

import sys

def is_balanced(input_string):

stack = []

for i in input_string:

if(i=="{"):

stack.append("{")

elif(i=="}"):

stack.pop()

if(len(stack)==0):

return True

else:

return False

if __name__ == '__main__':

try:

_input_string = sys.argv[1]

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

except:

print("String can't be empty")

Kindly check the attached image below to see the code screenshot and code output.

You might be interested in
Aapke question about computer keyboard​
Lapatulllka [165]

Explanation:

A computer keyboard is an input device that allows a person to enter letters, numbers, and other symbols (these are called characters in a keyboard) into a computer. It is one of the most used input devices for computers. Using a keyboard to enter lots of data is called typing

8 0
3 years ago
season is when the weather is not optimal and few tourists of vacation time a shoulder b high c average d low​
cricket20 [7]
Winter is such a season. Travel is lower to colder climate areas such as Canada, but higher to warmer climate areas like Columbia.
7 0
3 years ago
Read 2 more answers
What is the value of count after this nested FOR loop executes fully.
Alisiya [41]

Answer:

168 (although the =< must be corrected to <=)

Explanation:

int count = 0;

for (int row = 4; row <= 15; row++)

for (int col = 0; col < 13; col = col +2)

count+=2;

The inner for loop runs 7 times (for col = 0,2,4,6,8,10,12). Anything higher is not less than 13. Therefore the inner loop increments count by 2 seven times, i.e. it increments count by 14.

The outer for loop runs 12 times (for row = 4,5,6,7,8,9,10,11,12,13,14,15).

If the count is incremented by 14 twelve times, you are incrementing it by 14*12 = 168.

Therefore the count goes from 0 to 168 after the nested loops.

5 0
3 years ago
Flexplace and telecommuting are similar in that both allow you to _____. work in a location away from the office work different
viva [34]
Flexplace and telecommuting are similar in that both allow you to work in a different location four days a week. 
3 0
4 years ago
Which three are functions of the operating system?
Stels [109]

Answer:

An operating system has three main functions: (1) manage the computer's resources, such as the central processing unit, memory, disk drives, and printers, (2) establish a user interface, and (3) execute and provide services for applications software.

7 0
3 years ago
Read 2 more answers
Other questions:
  • What item on a business card is generally the most prominent?
    13·2 answers
  • With _______, applications are owned, delivered and managed remotely by one or more providers over the Internet or an intranet,
    15·1 answer
  • If you are involved in a collision that results in property damage, injury, or death, you must call
    13·1 answer
  • ______involves encoding information using fewer bits than the original representation Group of answer choices
    6·1 answer
  • Networking and telecommunications technologies, along with computer hardware, software, data management technology, and the peop
    5·1 answer
  • Pls help me<br> first one to answer correctly gets brainly points
    6·2 answers
  • Using Microsoft Word, write a 250-word essay on the fading of home telephone use with the advent of recent technology, and share
    14·1 answer
  • Software that allows users to use and adapt it for any purpose, often allowing the public to participate in further development
    7·2 answers
  • This isn't an academic question, but can anyone help me change the face on my apple watch to a picture from my camera roll? I've
    15·1 answer
  • Please help……Your friend is taking images from all over the internet without giving credit to the sources. He tells you that it’
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!