Part 4 Code Explanation and Use You are provided with the following two functions which you should 1. Analyse to determine what they do &
Part 4 Code Explanation and Use You are provided with the following two functions which you should 1. Analyse to determine what they do & provide documentation comments for, and 2. Incorporate into your final program solution. Wherever there is a # followed by some underscores in the code below, you should write a short comment explaining what the below section of code is doing, and if there is space why it is doing it. Do part 1 of the above in the provided assignment 1 template document, rather than here! # Function to: ___________________________ def get_float(prompt): # ____________________________________ value = float(0.0) # ____________________________________ while True: try: # ____________________________________ value = float(input(prompt)) # ____________________________________ if value < 0.0: print("We don't accept negative money!") continue # ____________________________________ break # ____________________________________ except ValueError: print('Please enter a valid floating point value.') # ____________________________________ return value # Function to: ___________________________ def bag_products(product_list): # ____________________________________ bag_list = [] non_bagged_items = [] MAX_BAG_WEIGHT = 5.0 # ____________________________________ for product in product_list: ITECH1400 Foundations of Programming School of Science, Engineering and Information Technology CRICOS Provider No. 00103D Page 5 of 7 # ____________________________________ if product.weight > MAX_BAG_WEIGHT: product_list.remove(product) non_bagged_items.append(product) # ____________________________________ current_bag_contents = [] current_bag_weight = 0.0 # ____________________________________ while len(product_list) > 0: # ____________________________________ temp_product = product_list[0] product_list.remove(temp_product) # ____________________________________ if current_bag_weight + temp_product.weight <= MAX_BAG_WEIGHT: # ____________________________________ current_bag_contents.append(temp_product) current_bag_weight += temp_product.weight # ____________________________________ else: bag_list.append(current_bag_contents) # ____________________________________ current_bag_contents = [temp_product] current_bag_weight = temp_product.weight # ____________________________________ if (len(product_list) == 0): bag_list.append(current_bag_contents) # ____________________________________ for index, bag in enumerate(bag_list): output = 'Bag ' + str(index + 1) + ' contains: ' # ____________________________________ for product in bag: output += product.name + '\t' print(output, ' ') # ____________________________________ if (len(non_bagged_items) > 0): output = 'Non-bagged items: ' # ____________________________________ for item in non_bagged_items: output += item + '\t' print(output,' ')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started