https://https://moodle.federation.edu.au/mod/resource/view.php?id=3090397/mod/resource/view.php?id=3073193

1 answer below »
https://https://moodle.federation.edu.au/mod/resource/view.php?id=3090397/mod/resource/view.php?id=3073193
Answered Same DayDec 24, 2020ITECH1400

Answer To: https://https://moodle.federation.edu.au/mod/resource/view.php?id=3090397/mod/resource/view.php?id=3...

Ximi answered on Jan 04 2021
136 Votes
36107/recyclingmachine.py
from recyclableItem import RecyclableItem
class RecyclingMachine(object):
"""
Class Implementation of Recycling Machine
"""
#Constructor
def __init__(self):
self.price_list = {
"can": 0.20,
"metal": 0.50,
"paper": 0.10,
"plast
ic":0.10,
}
self.weight_list = {
"can": 10,
"metal": 15,
"paper": 2,
"plastic": 2,
}
self.amount = 0
self.accepted_items = []
def select_product(self):
#Menu display
item_list = []
while True:
name = input("Balance: ${} . Please select a product: (Can, Metal, Paper, Plastic, STOP) ".format(self.amount))
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.amount += 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 as per instructions
self.accepted_items = []
non_accepted = []
MAX_WEIGHT = 15.0
self.amount = 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.amount += temp_item.price
# append to products when list finishes
else:
print ("Bag full")
# contents loop
for index, bag in enumerate(self.accepted_items):
# print all items to user
for item in bag:
output = 'Machine ' + str(index + 1) + ' contains: '
print(output+item.name, '\n')
# if non accepted items exist
if (len(non_accepted) > 0):
output = 'Non-bagged items: '
# print all non-accepted items
for item in non_accepted:
output += item + '\t'
print(output,'\n')

def identify_item(self, name):
#Checking if Item exists or not
return name in self.price_list.keys()
def payout(self, amount):
#Payment mode is cash
def get_int(prompt):
#Implementing from template
value = int(0)
while True:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here