Question: Could someone fix the main function code so everything runs smoothly. I also gave the other 2 sets of code for the main one RetailItem:

Could someone fix the main function code so everything runs smoothly. I also gave the other 2 sets of code for the main one

RetailItem:

class RetailItem:

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

self.__item_description = description

self.__units_in_inventory = units

self.__price = price

def set_item(self, item):

self.__item_description = description

def set_units_in_inventory(self, units):

self.__units_in_inventory = units

def set_price(self, price):

self.__price = price

def get_item_description(self):

return self.__item_description

def get_units_in_invenotry(self):

return self.__units_in_inventory

def get_price(self):

return self.__price

def __str__(self):

return 'Item Description:' + self.__item_description, \

'\tNumber of Units:' + self.__units_in_inventory, \

'\tPrice: $' + self.__price

def decrementInventory(units):

if units > 0:

units -= 1

else:

units = 0

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CashRegister

import RetailItem

class CashRegister:

def __init__(self):

self.__items = []

def clear(self):

self.__items = []

def purchase_item(self, retail_item):

self.__items.append(retail_item)

print("The item was added to the cash register.")

def get_total(self):

total = 0.0

for item in self.__items:

total = total + item.get_price()

return total

def show_items(self):

print('The items in the cash register are:')

print()

for item in self.__items:

print(item)

print()

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

FIX THIS ONE PLEASE AND THANK YOU

main function

import RetailItem

import CashRegister

PANTS = 1

SHIRT = 2

DRESS = 3

SOCKS = 4

SWEATER = 5

def main():

pants = retail.RetailItem('Pants', 10, 19.99)

shirt = retail.RetailItem('Shirt', 15, 12.50)

dress = retail.RetailItem("Dress", 3, 79.00)

socks = retail.RetailItem("Socks", 50, 1.00)

sweater = retail.RetailItem("Sweater", 5, 49.99)

sale_items = {PANTS:pants, SHIRT:shirt, \

DRESS:dress, SOCKS:socks, SWEATER:sweater}

register = cashRegister.CashRegister()

checkout = 'N'

while checkout=='N':

user_choice = get_user_choice()

item = sale_items[user_choice]

if item.get_inventory() == 0:

print("The item is out of stock.")

else:

register.purchase_item(item)

new_item = retail.RetailItem(item.get_description(),\

item.get_inventory()-1,\

item.get_price())

sale_items[user_choice] = new_item

print()

print("Your purchase total is: ", format(register.get_total(),'.2f'))

print()

register.show_items()

register.clear()

def get_user_choice():

print("Menu")

print('---------------------------------')

print('1. Pants')

print('2. Shirt')

print('3. Dress')

print('4. Socks')

print('5. Sweater')

print()

choice = int(input("Enter the menu number of the item " +\

"you would like to purchase: "))

print()

while choice > SWEATER or choice < PANTS:

while choice > SWEATER or choice < PANTS:

print()

return choice

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!