Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are provided with the following two functions which you should Analyse to determine what they do & provide documentation comments for, and Incorporate into

You are provided with the following two functions which you should

Analyse to determine what they do & provide documentation comments for, and

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:

CRICOS Provider No. 00103D Page 4 of 7

ITECH1400 Foundations of Programming School of Science, Engineering and Information Technology

# ____________________________________

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,' ')

language python

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago