Question: Modify the program to get the answer in sample session without using the global keywords and change the length of the stack. size = 0

![= 0 stack = [None) * 3 def print_stack(size): if stack [0]](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3a926b0aae_58266f3a9264bea4.jpg)
size = 0 stack = [None) * 3 def print_stack(size): if stack [0] == None: print("{}") else: print("{", end="") for w in stack: if w!=None: print("{w}", end=" ") print("}") def add(number): new_size = size stack [new_size] = str(number) new_size+=1 print_stack(new_size) return new_size def remove(): new_size = size new_size-=1 stack [new_size] = None print_stack(new_size) return new_size 1 def main(): while True: print_stack(size) user_input = input ("Enter command:) n = int(input("Enter a new number:")) if user_input == "a": size = add(n) elif user_input == "r": size = remove() BE elif user_inpu print("Bye!") break main() UnboundLocalError Traceback (most recent call last)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
