Overall, this script creates a menu-driven interface where the user can add elements to a queue, remove elements from the queue, display the elements in the queue, or exit the program. If the user enters an invalid choice (other than `’1’`, `’2’`, `’3’`, or `’4’`), we display a message indicating that the choice is invalid, and the loop continues to prompt the user for another choice. If the user enters `’4’`, we display a message indicating that the program is exiting, and then we break out of the loop, ending the program. If the queue is empty, we display a message indicating that the queue is empty. If the queue is not empty, we print all the elements in the queue using a `for` loop. If the user enters `’3’`, we again check if the queue is not empty (`len(queue) > 0`). If the queue is not empty, we use the `popleft()` method to remove the element at the front of the queue, and we print the removed element. If the user enters `’2’`, we first check if the queue is not empty (`len(queue) > 0`). Print(“Removed element:”, removed_element) We display a message indicating that the element has been added to the queue. The element is then appended to the end of the queue using the `append()` method. If the user enters `’1’`, we prompt them to enter an element to add to the queue using the `input()` function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |