Question

In: Computer Science

Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Task 2...

Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested.

Task 2

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”.

       

Solutions

Expert Solution

Answer:

Approach 1:

Program:

product_type = input("Enter the product type (A or B): ") # taking product type from the keyboard (a string value)
weight = float(input("Enter the weight of the product: ")) # taking weight from the keyboard (string value is converted to float)

if product_type is 'A' : # if 'product_type' is 'A'
if weight > 10: # if weight is greater than 10
print("The product is defective") # prints "product is defective"
else: # if weight is less than or equal to 10
print("The product is normal") # prints "product is normal"
elif product_type is 'B': # if 'product_type' is 'B'
if weight > 15: # if weight is greater than 15
print("The product is defective") # prints "product is defective"
else: # if weight is less than or equal to 15
print("Product is normal") # prints "product is normal"
  
Program screenshot:

Output:

Approach 2:

Program:

product_type = input("Enter the product type (A or B): ") # taking product type from the keyboard (a string value)
weight = float(input("Enter the weight of the product: ")) # taking weight from the keyboard (string value is converted to float)

# if the product_type is 'A' and weight > 10 or if the product_type is 'B' and weight > 15
if ((product_type is 'A') and (weight > 10)) or ((product_type is 'B') and (weight > 15)) :   
print("The product is defective") # prints "product is defective"
else: # if the product_type is 'A' and weight <= 10 or if the product_type is 'B' and weight <= 15
print("The product is normal") # prints "product is normal"

Program screenshot:

Output:


Related Solutions

Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Given two...
Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Given two exam scores, exam_1 and exam_2, write a program to determine if the student makes progress (exam_2 is greater than exam_1). Return “Yes” or “No”. You can use any exam_1 score and exam_2 score for this exercise.
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to print the type of the following variables. Please write down the codes and the output as well. x = 3.5 y = '3.5' z = {1:'John', 2:'Wick', 3:'Barry', 4:'Allen'}
Please attach to the application a brief narrative outlining your academic interests. Include any current or...
Please attach to the application a brief narrative outlining your academic interests. Include any current or long-range interests in research, teaching or other professional objectives. If you have progressed far enough in your career to have publications or other evidence of scholarly endeavor, please describe these. plzzz ans asap...
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives •...
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives • Be able to write methods • Be able to call methods Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct...
TASK: ( answers should be computerized and in details - please do not copy and paste...
TASK: ( answers should be computerized and in details - please do not copy and paste - about 1500 words ) Select an organization of your choice and carry out the following tasks. Conduct a research on the marketing and promotional strategies of the organization selected. Your Report should include the following: 1. Introduction 2. Summarize the various promotional strategies used by the organization in implementing an Integrated Marketing Strategy. Identify the risks associated with promotional campaigns and discuss how...
Please in C++, show screenshots of output plus .txt file. thanks Breakfast Billing System Write a...
Please in C++, show screenshots of output plus .txt file. thanks Breakfast Billing System Write a program to help a local restaurant automate its breakfast billing system. The program should do the following: Show the customer the different breakfast items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right...
Make a calculator in python that always gives an explanation when the answer is output. It...
Make a calculator in python that always gives an explanation when the answer is output. It must be detailed
(Please use Python) Suppose that a company sells five products with product codes p101, p107, p122,...
(Please use Python) Suppose that a company sells five products with product codes p101, p107, p122, p125, and p126. The company has three warehouses, which are located in St. Louis, Chicago, and Kansas City. The retail value for each of the five products and the inventory for each of the warehouses are stored in dictionaries, as shown below. Copy the code below into a code cell, and then execute that cell. prices = {'p101':37.52, 'p117':56.98, 'p122':43.72, 'p125':48.33, 'p126':52.45} inventory =...
using python: Given an arbitrary whole number, please write an if statement to output if it...
using python: Given an arbitrary whole number, please write an if statement to output if it is an even number or an odd number
Cryptography - please use Python to complete the following task. You don't have to implement AES...
Cryptography - please use Python to complete the following task. You don't have to implement AES just import the necessary libraries. Can you fix my code? Thanks! Read in a 128 bit key from the user (16 characters). If the user enters a key of any other size it's fine to terminate the program with an error. Read in a string of arbitary length from the user. (ie, the string could be 1 character, or 50,000, or anywhere in between)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT