What's new

Python Patulong naman dito mga paps

Number Four

Forum Guru
Elite
Joined
Oct 18, 2017
Posts
1,851
Solutions
16
Reaction
2,637
Points
1,031
di ko talaga kasi makuha baka may idea kayo dito. Maraming salamat!




Lab Exercise # 4 - Circular Queues

A restaurant accepts a maximum number (5) of orders at a time. The customers are served on a first come, first served basis. Orders are served every 60 seconds and cannot be cancelled once they are placed. Every time an order is served, a slot in the queue will become available and a new order can be taken.

Write a program that will implement this restaurant order system using a circular queue. The program will do the following:

1. Place customers in a queue.

2. Display whether the queue is full or not.

3. If not yet full, the queue will take in orders until max number of orders is reached.

4. If full, the queue cannot take in an order.

5. Every 60 seconds, an order will be served and will be taken out of the queue. Program displays a prompt allowing new order into the queue.

Example execution:

Enter customers:
a
b
c
d
e
queue is: a, b, c , d, e
Reservation queue is full!
[After 60 seconds] - 1 slot is available.
Enter a new customer: f
queue is: b, c, d, e, f
 
I will do it like this.

Hope this helps. Nilagyan ko ng comments for you to understand how it happened lol
Python:
from ast import If
import time

# A basic function to check if reservation is full
def reservationCheck(x, y):

    if len(x) == y:
        print("Reservation is full!")
        print("Current Queue: ",*x)
        return True
    elif len(x) < y:
        queue.append(input("Enter a new customer: "))
        print("Current Queue: ",*x)
        return False



# Declare and initialize queue size
queueLimit = int(input("Enter reservation limit: "))
queue = []

# Input customers to your queue
for customers in range(queueLimit):
    queue.append(input("Enter Customers: "))

# Check the queue after the initialization
check = reservationCheck(queue, queueLimit)

# Do the work
if check == True:
    while len(queue) == queueLimit:
        print(" * Processing Work *")
        time.sleep(5) # 5 Seconds lang nilagay ko para mabilis, change it to you liking ie: 60
        print("Customer ", queue[0], " processed.")
        # This will remove the very first customer on the list
        queue.pop(0)
        reservationCheck(queue, queueLimit)
 
uy kinsa ka?
ikaw ni kim?

I will do it like this.

Hope this helps. Nilagyan ko ng comments for you to understand how it happened lol
Python:
from ast import If
import time

# A basic function to check if reservation is full
def reservationCheck(x, y):

    if len(x) == y:
        print("Reservation is full!")
        print("Current Queue: ",*x)
        return True
    elif len(x) < y:
        queue.append(input("Enter a new customer: "))
        print("Current Queue: ",*x)
        return False



# Declare and initialize queue size
queueLimit = int(input("Enter reservation limit: "))
queue = []

# Input customers to your queue
for customers in range(queueLimit):
    queue.append(input("Enter Customers: "))

# Check the queue after the initialization
check = reservationCheck(queue, queueLimit)

# Do the work
if check == True:
    while len(queue) == queueLimit:
        print(" * Processing Work *")
        time.sleep(5) # 5 Seconds lang nilagay ko para mabilis, change it to you liking ie: 60
        print("Customer ", queue[0], " processed.")
        # This will remove the very first customer on the list
        queue.pop(0)
        reservationCheck(queue, queueLimit)
maraming thank you paps!
 

Similar threads

Back
Top