<div dir="ltr"><div>I've written the code below the assignment, and I think I have everything covered in terms of asking the user for the information I need and somehow calculating costs, but I'm just ridiculously confused on the order and placement of the functions and components of this program- specifically the shiprate variable. Thank you in advance for any help.<br>
</div><div><br></div>This is my assignment:<div><p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Write a program that asks a user
for the name of a product that they are ordering online and its weight. The program must calculate the cost of
shipping the product using the following cost structure. If it weighs less than 10 pounds the cost is
$1.50 per pound, if it is 10 pounds or more and less than 25 pounds then the
cost is $1.45 per pound. If the weight
is 25 pounds or more the cost is $1.40 per pound. You may get the data from the user in
main. You must print the name of the
product, the weight and the cost of shipping in a separate function.</span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> </span></p>
<p class="MsoNormal"><b><u><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">*********NOTE: ALWAYS USE “WHILE LOOPS” To Validate*******************</span></u></b></p><p class="MsoNormal"><b><u><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"><br>
</span></u></b></p><p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal"> </p><p class="MsoNormal"><br></p><p class="MsoNormal"># This program uses an if-else statement</p>
<p class="MsoNormal"># It asks for the name of a product and the weight of that product.</p><p class="MsoNormal"># It then determines the shipping cost as defined by the weight.</p><p class="MsoNormal">#</p><p class="MsoNormal">
# Variable Type Purpose</p><p class="MsoNormal"># product string hold for name of product</p><p class="MsoNormal"># weight float hold for weight of product</p><p class="MsoNormal">
#</p><p class="MsoNormal"><br></p><p class="MsoNormal">def main ():<br></p><p class="MsoNormal"> </p><p class="MsoNormal"> product = input("Please enter the name of the product: ") </p><p class="MsoNormal">
weight = int(input("Please enter the weight of the product: "))</p><p class="MsoNormal"><br></p><p class="MsoNormal"> print('Product:', product)</p><p class="MsoNormal"> print('Weight:', weight)</p>
<p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal"> if weight <= 10:</p><p class="MsoNormal"> shiprate = 1.5</p><p class="MsoNormal"> calc_weight_small(weight, shiprate)</p>
<p class="MsoNormal"> elif weight >= 10 and weight <= 25:</p><p class="MsoNormal"> shiprate = 1.45</p><p class="MsoNormal"> calc_weight_medium(weight, shiprate)</p><p class="MsoNormal"> else:</p>
<p class="MsoNormal"> shiprate = 1.4</p><p class="MsoNormal"> calc_weight_large(weight, shiprate)</p><p class="MsoNormal"><br></p><p class="MsoNormal"># Calculate shipping cost for product less than 10 pounds</p>
<p class="MsoNormal">def cacl_weight_small(weight, shiprate):</p><p class="MsoNormal"> shiprate = 1.5</p><p class="MsoNormal"> total = weight * shiprate</p><p class="MsoNormal"># Calculate shipping cost for product between 10 and 25 pounds.</p>
<p class="MsoNormal">def calc_weight_medium(weight, shiprate):</p><p class="MsoNormal"> shiprate = 1.45</p><p class="MsoNormal"> total = weight * shiprate</p><p class="MsoNormal"># Calculate shipping cost for product over 25 pounds.</p>
<p class="MsoNormal">def calc_weight_large(weight, shiprate):</p><p class="MsoNormal"> shiprate = 1.4</p><p class="MsoNormal"> total = weight * shiprate</p><p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal">
#</p><p class="MsoNormal">#This function calculates and prints the total cost</p><p class="MsoNormal"># based on the weight category the product falls into</p><p class="MsoNormal"># Variable Type Purpose</p>
<p class="MsoNormal"># weight float weight of product</p><p class="MsoNormal"># shiprate float cost per pound</p><p class="MsoNormal"># total float total cost to ship product</p>
<p class="MsoNormal">#</p><p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal"> print ()</p><p class="MsoNormal"> print ("The cost to ship", product, "is: $", format (total, '9,.2f'))</p>
<p class="MsoNormal"> </p><p class="MsoNormal"> </p><p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal"> </p><p class="MsoNormal"><br></p><p class="MsoNormal"><br></p><p class="MsoNormal">
main ()</p></div></div>