Write a Python application using the concepts of multithreading for a flower
shop where flowers are delivered based on order.
SOLUTION CODE FOR ABOVE QUESTION
import threading
#A function to check whether the flowers to be delivered
# are available and confirm delivery of the requested number of flowers
def flower_delivery():
stock_available =int(input("Enter the number of flowers remaining in the stock: "))
stock_to_deliver =int(input("Enter the number of flowers to deliver: "))
destination = input("Enter the destination address: ");
if stock_available < stock_to_deliver:
print("\nThere are no enough flowers to deliver!")
else:
#decreament the stock by the number of flowers to be delivered
stock_available = stock_available - stock_to_deliver;
print(str(stock_to_deliver) + " flowers has been delivered to " + str(destination))
print("Remaining number of flowers in the stock is " + str(stock_available));
#Create a thread
my_flower_delivery = threading.Thread(target=flower_delivery(), args=())
#Start thread
my_flower_delivery.start()
my_flower_delivery.join()
print("\nThread execution is complete!")
SAMPLE OUTPUT OF THE PROGRAM
Comments
Leave a comment