Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
143 views
in Computer by (51.9k points)
closed by

Write a menu driven python program using queue, to implement movement of shuttlecock in its box.

1 Answer

+1 vote
by (49.5k points)
selected by
 
Best answer
#   initializing empty myQueue

myQueue = list()

#   index stores the shuttle number

index = 0 

#   functions that define operation of the queue data structure

def enqueue(myQueue, element):

    myQueue.append(element)

def isEmpty(myQueue):

    if len(myQueue)==0:

        return True

    else:

        return False

        def dequeue(myQueue):

    if not (isEmpty(myQueue)):

        return myQueue.pop(0)

    else :

        return "Box is empty"

def size(myQueue):

    return len(myQueue)

#   infinite loop so that it continues as many times the user wants

while(True):

    #   display the menu to the user

    print("Menu")

    print("1. Insert a shuttlecock 2. Remove a shuttlecock 3. Display number of shuttlecock 4.exit ")

    choice = int(input("Enter your choice"))

    # if usre enters 1 then do this 

    if choice == 1:

        index+=1

        enqueue(myQueue,index)

        print("Shuttle added")

        continue

    elif choice == 2:

        removedshuttle = dequeue(myQueue)

        print("The shuttle removed is : ",removedshuttle)

        continue

    elif choice == 3:

        print("The number of shuttles in the box = ",size(myQueue))

        continue

    elif choice == 4:

        break

    else:

        print("Wrong choice.")

Related questions

0 votes
1 answer
asked Mar 7, 2023 in Computer by TejasZade (51.9k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 7, 2023 in Computer by TejasZade (51.9k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...