Python coding

  

We are producing two types of products, product A and product B. Product A is defective if the weight is greater than 10 lbs. Product B is defective if the weight is greater than 15 lbs. For a given product, we know its product_type and its weight. Design a program to screen out defective products. Starting the program with variable definition:

product_type = ‘xxx’

weight = xxx

Hint: You need to figure out the product type first, and then check if the product is defective based on the weight. You may use a nested if statement like the following:

if product is A:

if product weight > 10:

the product is defective

else:

if product weight >15:

the product is defective

But you need to translate the English into Python codes. 

As a challenge, you may also try a one-step if statement. such as :

if some condition is met:

the product is defective

else:

the product is normal

And the key is the bolded “some condition”.

Tags: No tags