This is the code I have so far:
def convertWeight():
(totalWeight * 0.45359237)
def getRate():
if totalWeight <= 2:
rate = totalWeight * 1.10
elif totalWeight > 2 and totalWeight <= 6:
rate = totalWeight * 2.20
elif totalWeight > 6 and totalWeight <= 10:
rate = totalWeight * 3.70
elif totalWeight > 10:
rate = totalWeight * 4.20
numBoxes = int(input('Please enter the number of boxes: '))
unit = input('Please enter the unit of measurement, Imperial or Metric (as I or M): ')
while unit != 'I' or 'M' or 'i' or 'm':
unit = input('Please enter the unit of measurement again, Imperial or Metric (as I or M): ')
while unit == 'I' or 'M' or 'i' or 'm':
for x in range(numBoxes):
weight = float(input('Please enter the weight of the boxes: '))
totalWeight = 0
totalWeight = totalWeight + weight
if unit == 'M':
totalWeight = convertWeight
else:
totalWeight = totalWeight
getRate(totalWeight)
transportCost = getRate * totalWeight
print('The number of boxes is {0}, the total weight is {1:.2f}, and the transport cost is {2:,}.' .format(numBoxes, totalWeight, transportCost))
How do I firstly, loop unit input until I, i, M, or m, are inputted, and then break the loop and continue? And how do I secondly, calculate the transport cost, that is, get the rate from the function created, and then times it by totalWeight?
Thanks everyone.