Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

How can I modify the program in order to get the asnwer shown in the sample session image text in transcribed
image text in transcribed
image text in transcribed
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) 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

1.Which are projected Teaching aids in advance learning system?

Answered: 1 week ago