1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lorasvet [3.4K]
4 years ago
6

Write a Python program that can compare the unit (perlb) cost of sugar sold in packages with different weights and prices. The p

rogram prompts the user to enter the weight and price of package 1, then does the same for package 2, and displays the results to indicate sugar in which package has a better price. It is assumed that the weight of all packages is measured in lb. The program should check to be sure that both the inputs of weight and price are both positive values.

Computers and Technology
1 answer:
Virty [35]4 years ago
4 0

Answer:

<em>This program is written using python</em>

<em>It uses less comments (See explanation section for more explanation)</em>

<em>Also, see attachments for proper view of the source code</em>

<em>Program starts here</em>

<em></em>

#Prompt user for price of package 1

price1 = int(input("Enter Price 1: "))

while(price1 <= 0):

     price1 = int(input("Enter Price 1: "))

#Prompt user for weight of package 1

weight1 = int(input("Enter Weight 1: "))

while(weight1 <= 0):

     weight1 = int(input("Enter Weight 1: "))

#Calculate Unit of Package 1

unit1 = float(price1/weight1)

print("Unit cost of Package 1: "+str(unit1))

#Prompt user for price of package 2

price2 = int(input("Enter Price 2: "))

while(price2 <= 0):

     price2 = int(input("Enter Price 2: "))

#Prompt user for weight of package 2

weight2 = int(input("Enter Weight 2: "))

while(weight2 <= 0):

     weight2 = int(input("Enter Weight 2: "))

#Calculate Unit of Package 2

unit2 = float(price2/weight2)

print("Unit cost of Package 2: "+str(unit2))

#Compare units

if unit1 > unit2:

     print("Package 1 has a better price")

elif unit1 == unit2:

     print("Both Packages have the same price")

else:

     print("Package 2 has a better price")

<em></em>

Explanation:

price1 = int(input("Enter Price 1: ")) -> This line prompts the user for price of package 1

The following while statement is executed until user inputs a value greater than 1 for price

while(price1 <= 0):

     price1 = int(input("Enter Price 1: "))

weight1 = int(input("Enter Weight 1: ")) -> This line prompts the user for weight of package 1

The following while statement is executed until user inputs a value greater than 1 for weight

while(weight1 <= 0):

     weight1 = int(input("Enter Weight 1: "))

unit1 = float(price1/weight1) -> This line calculates the unit cost (per weight) of package 1

print("Unit cost of Package 1: "+str(unit1)) -> The unit cost of package 1 is printed using this print statement

price2 = int(input("Enter Price 2: ")) -> This line prompts the user for price of package 2

The following while statement is executed until user inputs a value greater than 1 for price

while(price2 <= 0):

     price2 = int(input("Enter Price 2: "))

weight2 = int(input("Enter Weight 2: ")) -> This line prompts the user for weight of package 2

The following while statement is executed until user inputs a value greater than 1 for weight

while(weight2 <= 0):

     weight2 = int(input("Enter Weight 2: "))

unit2 = float(price2/weight) -> This line calculates the unit cost (per weight) of package 2

print("Unit cost of Package 2: "+str(unit2)) -> The unit cost of package 2 is printed using this print statement

The following if statements compares and prints which package has a better unit cost

  • <em>If unit cost of package 1 is greater than that of package 2, then package 1 has a better price</em>
  • <em>If unit cost of both packages are equal then they both have the same price</em>
  • <em>If unit cost of package 2 is greater than that of package 1, then package 2 has a better price</em>

if unit1 > unit2:

     print("Package 1 has a better price")

elif unit1 == unit2:

     print("Both Packages have the same price")

else:

     print("Package 2 has a better price")

You might be interested in
What does enterprise operating system mean?
Alla [95]
It means the operating system used in enterprise.
When a corporation needs 100 computers to have OS, it has to order enterprise OS packages from M$.
7 0
4 years ago
ystem, the design of which was developed using customary structured methods. To manage the intricacy of the application developm
Soloha48 [4]

Answer:

Organized plan is utilized to change the auxiliary examination (for example modules and their interrelation) into a straightforward graphical structure. It is essentially done in two stages:  

1. Transform Analysis  

2. Transaction Analysis  

For showing control stream in organized investigation we use Flow diagrams, But for indicated choice in organized examination, we frequently use choice tree. In choice tree we use hover for current state. An example decision tree is attached with the appropriate response, benevolently allude the equivalent.

4 0
3 years ago
The _____ document, created during the requirements-gathering and analysis phase of the systems development life cycle (SDLC), i
daser333 [38]

Answer:

The answer to this question is the option "a".

Explanation:

In computer science, the term SDLC stands for Software Development Life Cycle or it is also known as the System Development Life Cycle. This process used by the software industry to produce high-quality software. It aims to produce high-quality software that fulfills customer expectations. The term system specifications is a part of the SDLC. In this part we check the software support the system or not so the answer to this question is system specifications.

6 0
3 years ago
Read 2 more answers
Please answer this now I need please.
choli [55]

Answer:

You can change the color of text in your Word document. Select the text that you want to change. On the Home tab, in the Font group, choose the arrow next to Font Color, and then select a color.

You can display a graphics window and draw colorful shapes in it if you use the Show operation of the GraphicsWindow object. You can also specify properties of the graphics window, such as its title, height, width, and background color.

Explanation: Sorry I couldn't do the third question but hope it helps.

7 0
3 years ago
A content team can create a custom board in Hootsuite Analytics with widgets displaying how their content is resonating with the
valkas [14]
<span>you might include things like total clicks, clicks by country, or reaction topics</span>
8 0
3 years ago
Read 2 more answers
Other questions:
  • Create a Flash Card class. Flash Cards have a Question and an Answer, each of which are Strings. Your class should include a con
    6·1 answer
  • Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output tho
    9·1 answer
  • What is the difference between a learner’s license and a driver’s license?
    12·1 answer
  • Assume there is a Mac and a HP computer each has an Intel microprocessor. Would an assembly program produced using the Mac compu
    13·1 answer
  • Bob gets an e-mail addressed from his bank, asking for his user ID and password. He then notices that the e-mail has poor gramma
    6·1 answer
  • 21
    5·1 answer
  • Which of these does an operating system use to organize files?
    7·2 answers
  • Within a master slide template, you can create a custom slide layout. Place the steps to complete this task in the correct order
    14·1 answer
  • WRITE A PROGRAM TO CALCULATE SIMPLE INTEREST
    12·1 answer
  • Which of the following is NOT true about a USB stick?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!