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

Modify the program to get the answer in sample session without using the global keywords and change the length of the stack.  Modify the program to get the answer in sample session without
using the global keywords and change the length of the stack. size
= 0 stack = [None) * 3 def print_stack(size): if stack [0]

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) in () 44 break 45 ---> 46 main() in main() 32 def main(): 33 while True: ---> 34 print_stack (size) 35 user_input - input("Enter command: ") 36 n - int(input("Enter a new number:")) UnboundLocalError: local variable size' referenced before assignment 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!