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
Assume you have 100 values that are all different, and use equal width discretization with 10 bins.
zepelin [54]

Answer:

a) 10

b) 1

C) 10

D) 1

E) 20

F)  10

Explanation:

a) The largest number of records that could appear in one bin

 = 10

B) The smallest number of records that could appear in one bin

= 1

C) The largest number of records that cab appear in one bin

= 10

d) smallest number

= 1

e) With frequency = 20. the largest number of records that could appear in one bin with equal width discretization (10 bins)

= 20

f ) with equal height discretization

= 10

6 0
3 years ago
a new client has indicated that they are exercising due to advice from their physician, but they are generally amotivated. what
Orlov [11]

The factor that is a best choice for the personal trainer in their initial meeting is option a: Inquire further about what their motives are for participating.

<h3>What are the motives in motivation?</h3>

Psychologists is known to have shared motives into three types which are:

  • Biological motives
  • Social motives
  • Personal motives.

Note that the goal that is to be meant is for the fulfillment of  the client want or their  need.

Therefore asking the right question will go a long way in satisfying them. So, The factor that is a best choice for the personal trainer in their initial meeting is option a: Inquire further about what their motives are for participating.

Learn more about personal trainer from

brainly.com/question/19462080
#SPJ1

A new client has indicated that they are exercising due to advice from their physician, but they are generally amotivated. What would be the best choice for the personal trainer in their initial meeting?

Inquire further about what their motives are for participating.

Create a plan for overcoming barriers.

Establish short- and long-term goals.

Start establishing an emotional support system.

5 0
2 years ago
Which of the following students would be best suited to pursue a career in
Damm [24]

Answer:

<h3>B. Jill has strong computer skills and is interesting in design. She hopes to enter the work force within three years of grauduating high school...</h3>
4 0
3 years ago
Read 2 more answers
Software designed to penetrate security controls, identify valuable content, and then encrypt files and data in place in order t
rjkz [21]

Software designed to penetrate security controls, and to unlock the encryption is known as Ransomware .

<h3>What is Ransomware?</h3>

Ransomware is known to be a kind of malware set up or made to encrypt files on a device, and makes any files and the systems that rely on them to be unusable.

Note that Software designed to penetrate security controls, identify valuable content, and then encrypt files and data in place in order to extort payment for the key needed to unlock the encryption is known as Ransomware.

Learn  more about encryption from

brainly.com/question/9979590

#SPJ1

3 0
2 years ago
Which is an example of adaptive social behavior?
rusak2 [61]
<span>Birds help take care of each other's young to increase their chances of survival, and the behavior is passed on to offspring. 

Hope this helps!! :)</span>
6 0
3 years ago
Other questions:
  • Which option allows you to customize the order of your data ?
    14·2 answers
  • What would you enter at the command prompt to start a new bourne again shell session?
    14·1 answer
  • Write the program to solve quadratic equations, but if the discriminant is negative, output
    9·1 answer
  • Select the correct answer.
    12·2 answers
  • 1. Why is it important for IT technicians to keep documentation on computers for which they are
    13·1 answer
  • Draw a full binary tree of height 2. How many nodes does it have?
    5·1 answer
  • A recursive definition is a definition:____.
    14·1 answer
  • Why do we use compliment method?
    13·2 answers
  • Table Setting in any occasion can add to the beauty and significance of the event. It may
    6·1 answer
  • The CIBER network provides a link between the human resource and technology needs of a company with the research capacities and
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!