Question: python 100p, use the previously created push(functio... Since you need to reverse the whole string, and strings can have different lengths, the optimal way to


100p, use the previously created push(functio... Since you need to reverse the whole string, and strings can have different lengths, the optimal way to solve this is with the while - loop and the is_empty() function. You can get the length of a string with the len() function. Use the is_empty() function on the stack to check if the stack is empty or not. Did you use the is_empty() function? 1 #All function that you have implemented in the previous steps 2 def push(stack, new_item): 3 stack.append(new_item) 4 5 def is_empty(stack): 6 return stack == [] 7 8 def size( stack): 9 return len(stack) 10 11 #Do not change any code above this line. 12 13 I 14 def reverse_string(string): 15 #We have defined the stack for you 16 stack = [] 17 18 for char in string: 19 def push(stack, char): 20 stack.append(chex) #push to stack 31 x + main.py X starter_code.py He have us CU TIC LAN TOL you stack = [] 16 17 18 19 for char in string: def push(stack, char): stack.append(char) #push to stack 20 21 22 23 new_string=" 24 25 26 while not --- #Check if the stack is empty new_string += " + #pop the last element 27 return new_string 28 29 30 #Tests 31 #Do not change code below this line 32 assert reverse_string("programming") == "gnimmargorp" 33 print("Awesome job!") 34 print(reverse_string("programming")) 35
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
