see files
Answered Same DayJan 06, 2021

Answer To: see files

Amit answered on Jan 08 2021
162 Votes
36208/main.py
from recyclingmachine import RecyclingMachine
def run():
vm = RecyclingMachine()
next_customer = True
while next_customer:
vm.select_product()
vm.print_receipt()
while True:
answer = input("\n(N)ext customer, or (Q)uit?")
answer = ans
wer.upper()
if answer == "N":
    
break
elif answer == "Q":
exit()
else:
print("Invalid Response")
if __name__ == '__main__':
run()
36208/RecyclableItem.py
class RecyclableItem(object):
def __init__(self, name, weight=0, price=0):
#Constructor
self.name = name
self.weight = weight
self.price = price
36208/RecyclingMachine.py
from recyclableItem import RecyclableItem
class RecyclingMachine(object):
"""
Class Implementation of Recycling Machine
"""
def __init__(self):
#Constructor
self.balance = 0
self.price_list = {
"can": 0.20,
"bottle": 0.50,
"CD": 0.10,
"plastic":0.10,
}
self.weight_list = {
"can": 10,
"bottle": 15,
"CD": 2,
"plastic": 1,
}
self.accepted_items = []
def select_product(self):
#Menu display
item_list = []
while True:
name = input("Balance: ${} . Please select a product: (Can, Bottle, CD, Plastic, STOP) ".format(self.balance))
if name.lower() == "stop":
break
elif self.identify_item(name.lower()):

qty = input("How many %s do you have? "%name)

print ("Please place %d %s into the machine"%(int(qty), name))

for _ in range(int(qty)):
item_list.append(RecyclableItem(name, self.weight_list[name.lower()], self.price_list[name.lower()]))
self.balance += self.price_list[name.lower()]
print ("{} Added".format(name))
else:
print ("Item cant be recycled")
break
self.accept_item(item_list)

def accept_item(self, item_list):
#Implementing function from template
self.accepted_items = []
non_accepted = []
MAX_WEIGHT = 50.0
self.balance = 0
for item in item_list:
if item.weight > MAX_WEIGHT:
item_list.remove(item)
non_accepted.append(item)
current_contents = []
current_weight = 0.0
while len(item_list) > 0:
temp_item = item_list[0]
item_list.remove(temp_item)
if (len(item_list) == 0):
self.accepted_items.append(current_contents)

if current_weight + temp_item.weight < MAX_WEIGHT:
# appending to bag
current_contents.append(temp_item)
current_weight += temp_item.weight
self.balance += temp_item.price
# append to products when list finishes
else:
print ("Bag full")
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here