Question: How can I modify the program in order to get the asnwer shown in the sample session Sample Session {} Enter command: a- Enter a


Sample Session {} Enter command: a- Enter a new number: 10 {1} Enter command: a- Enter a new number: 20 {1, 2} Enter command: r- {1} Enter command: a- Enter a new number: 3- {1, 3} Enter command: q- Bye! 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
