Question: PYTHON: Consider the code from the previous example with an additional print command at the very end, and explain whether the value of result would

PYTHON:

Consider the code from the previous example with an additional print command at the very end, and explain whether the value of result would actually be output by that command.

def AbsDiff(input_value, std_value=24): ''' std_value and input_value are int Computes absolute difference and returns it as int ''' if input_value > std_value: result = input_value - std_value else: result = std_value - input_value return result

std_l = 24 in_l = int(input("Enter length: ")) l_diff = AbsDiff(input_value=in_l) in_w = int(input("Enter width: ")) w_diff = AbsDiff(input_value=in_w, std_value=18) print("Length var:", l_diff, "Width var:", w_diff) print(result)

Consider the following code, and outline what changes would be needed to the prt_rules function if it were to be defined outside of get_qty instead of nested within it:

def get_qty(product, ship=False): min_qty = 0 if ship: min_qty = 5 def prt_rules(): print("Orders must be integer values") print("Cannot order more than", max_qty) print("Order must be at least", min_qty) do_over = True while do_over: prt_rules() invalue = input("Enter order quantity for " + product + ": ") if invalue.isdigit(): qty = int(invalue) else: continue if min_qty <= qty <= max_qty: do_over = False return qty

print("Welcome!") max_qty = 50 qty_A = get_qty("A", True) qty_B = get_qty(product="B") total = qty_A * 10 + qty_B * 15 print("Total order cost: $",total)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!