程序代写代做代考 Programming Exercise 3-1

Programming Exercise 3-1

Programming Exercise 10-5

# retail.py

class RetailItem:

def __init__(self, description, inventory, price):

self.__description = description

self.__inventory = inventory

self.__price = price

def set_description(self, description):

self.__description = description

def set_inventory(self, inventory):

self.__inventory = inventory

def set_price(self, price):

self.__price = price

def get_description(self):

return self.__description

def get_inventory(self):

return self.__inventory

def get_price(self):

return self.__price

def __str__(self):

result = ‘Description: ‘ + self.get_description() + ‘
’ +

‘Units in inventory: ‘ + str(self.get_inventory()) +


Price: $’ + str(self.get_price())

return result

# Exercise 10-5.py

import retail

def main():

# Create three instances of RetailItem.

item1 = retail.RetailItem(‘Jacket’, 12, 59.95)

item2 = retail.RetailItem(‘Designer Jeans’, 40, 34.95)

item3 = retail.RetailItem(‘Shirt’, 20, 24.95)

# Display information.

print (‘Retail Item 1: ‘)

print (item1)

print()

print (‘Retail Item 2:’)

print (item2)

print()

print (‘Retail Item 3:’)

print (item3)

# Call the main function.

main()

Leave a Reply

Your email address will not be published. Required fields are marked *