<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Sorry, I sent this answer to the OP directly and not to the list.<br>
<div class="moz-forward-container"><br>
-------- Mensaje original --------
<table class="moz-email-headers-table" cellpadding="0"
cellspacing="0" border="0">
<tbody>
<tr>
<th align="RIGHT" nowrap="nowrap" valign="BASELINE">Asunto:
</th>
<td>Re: [Tutor] Passing arguments?</td>
</tr>
<tr>
<th align="RIGHT" nowrap="nowrap" valign="BASELINE">Fecha: </th>
<td>Sun, 20 Oct 2013 11:25:52 -0300</td>
</tr>
<tr>
<th align="RIGHT" nowrap="nowrap" valign="BASELINE">De: </th>
<td>Ricardo Aráoz <a class="moz-txt-link-rfc2396E" href="mailto:ricaraoz@gmail.com"><ricaraoz@gmail.com></a></td>
</tr>
<tr>
<th align="RIGHT" nowrap="nowrap" valign="BASELINE">A: </th>
<td>Jenny Allar <a class="moz-txt-link-rfc2396E" href="mailto:jennyallar@gmail.com"><jennyallar@gmail.com></a></td>
</tr>
</tbody>
</table>
<br>
<br>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<div class="moz-cite-prefix">El 20/10/13 01:20, Jenny Allar
escribió:<br>
</div>
<blockquote
cite="mid:CADXZeCb-iwh848BjptneWJgfJzz1cnTZiQ1qtvEM78Xa63UEeQ@mail.gmail.com"
type="cite">
<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>
</div>
</blockquote>
<br>
Ok, just a couple of things first. <br>
<br>
- Your assignment specifically says 'always use "while loops" to
validate' but I see no loop at all in your code. You might want to
look into it.<br>
<br>
- What your assignment points to when it says to use "while
loops" is that you should validate that what the user inputs is a
valid number. If the user will input something else than a number
as the weight then when you apply the int() function an exception
will be flagged and your program will terminate ungracefully. You
may validate input using "exceptions" and "while loops" (look it
up).<br>
<br>
- Your functions should do what their name imply, and preferably
do only one thing. Having a function named calc_weight_large()
that also prints the shipping cost is not good.<br>
<br>
- Your if asks for >= 10 and your elif for <= 10 when the "=
10" case was already handled by the first if, that is a mistake.
Besides which it might be better looking (though this is a matter
of personal preference) if you ::<br>
if weight > 25<br>
# do something<br>
elif weight > 10<br>
# do something else<br>
else<br>
# do something entirely different<br>
<br>
- I would structure the program in the following way ::<br>
def main():<br>
product = in_product()<br>
weight = in_weight()<br>
<br>
if weight > 25<br>
total = calc_shipping(1.40, weight)<br>
elif weight > 10<br>
total = calc_shipping(1.45, weight)<br>
else<br>
total = calc_shipping(1.50, weight)<br>
print_data(product, weight, total)<br>
<br>
<blockquote
cite="mid:CADXZeCb-iwh848BjptneWJgfJzz1cnTZiQ1qtvEM78Xa63UEeQ@mail.gmail.com"
type="cite">
<div dir="ltr">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>
# This program uses an if-else statement<br>
<br>
# It asks for the name of a product and the weight of that
product.<br>
# It then determines the shipping cost as defined by the
weight.<br>
#<br>
# Variable Type Purpose<br>
# product string hold for name of product<br>
# weight float hold for weight of
product<br>
#<br>
<br>
def main ():<br>
product = input("Please enter the name of the product:
") <br>
weight = int(input("Please enter the weight of the
product: "))<br>
<br>
print('Product:', product)<br>
print('Weight:', weight)<br>
<br>
if weight <= 10:<br>
shiprate = 1.5<br>
calc_weight_small(weight, shiprate)<br>
elif weight >= 10 and weight <= 25:<br>
shiprate = 1.45<br>
calc_weight_medium(weight, shiprate)<br>
else:<br>
shiprate = 1.4<br>
calc_weight_large(weight, shiprate)<br>
<br>
# Calculate shipping cost for product less than 10 pounds<br>
def cacl_weight_small(weight, shiprate):<br>
shiprate = 1.5<br>
total = weight * shiprate<br>
</div>
</div>
</blockquote>
<br>
<blockquote
cite="mid:CADXZeCb-iwh848BjptneWJgfJzz1cnTZiQ1qtvEM78Xa63UEeQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div># Calculate shipping cost for product between 10 and 25
pounds.<br>
def calc_weight_medium(weight, shiprate):<br>
shiprate = 1.45<br>
total = weight * shiprate<br>
</div>
</div>
</blockquote>
<br>
<blockquote
cite="mid:CADXZeCb-iwh848BjptneWJgfJzz1cnTZiQ1qtvEM78Xa63UEeQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div># Calculate shipping cost for product over 25 pounds.<br>
#<br>
#This function calculates and prints the total cost<br>
# based on the weight category the product falls into<br>
# Variable Type Purpose<br>
<br>
# weight float weight of product<br>
# shiprate float cost per pound<br>
# total float total cost to ship
product<br>
#<br>
def calc_weight_large(weight, shiprate):<br>
shiprate = 1.4<br>
total = weight * shiprate<br>
print ()<br>
print ("The cost to ship", product, "is: $",
format (total, '9,.2f'))<br>
<br>
main ()</div>
</div>
<br>
</blockquote>
<br>
<br>
</div>
<br>
</body>
</html>