Answer:
Check the explanation
Step-by-step 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.