A class priority aoir mail
Here is a Python class that simulates a priority air mail system:
class PriorityAirMail:
def __init__(self):
self.packages = []
def add_package(self, package):
self.packages.append(package)
def send_packages(self):
self.packages.sort(key=lambda x: x.priority, reverse=True)
for package in self.packages:
print(f"Sending package {package.name} with priority {package.priority}.")
class Package:
def __init__(self, name, priority):
self.name = name
self.priority = priority
# Example usage:
mail = PriorityAirMail()
package1 = Package("Package 1", 3)
package2 = Package("Package 2", 1)
package3 = Package("Package 3", 2)
mail.add_package(package1)
mail.add_package(package2)
mail.add_package(package3)
mail.send_packages()
In this example, we have a PriorityAirMail
class that has a list of packages. Each package has a name and a priority. The add_package
method adds a package to the list, and the send_packages
method sorts the packages by priority in descending order and then sends them.
The Package
class is a simple class that represents a package with a name and a priority.
In the example usage, we create three packages with different priorities and add them to the mail. Then we call the send_packages
method to send the packages. The output will be:
Sending package Package 1 with priority 3.
Sending package Package 3 with priority 2.
Sending package Package 2 with priority 1.