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...
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string...
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as...
USE Python 2.7(screen shot program with output) the task is: takes in a list of protein...
USE Python 2.7(screen shot program with output) the task is: takes in a list of protein sequences as input and finds all the transmembrane domains and returns them in a list for each sequence in the list with given nonpolar regions and returns the lists for those. 1. This code should call two other functions that you write: regionProteinFind takes in a protein sequence and should return a list of 10 amino acid windows, if the sequence is less than...
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 =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT