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]
3 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]3 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
So I was wondering how I should get into Game Development?
Hunter-Best [27]
Tbh i depends on what kind of person you are. If you really like video games then go ahead but i guess what you are asking is how and that really doesnt answr your question but 
1) YOU HAVE TO BE FULLY COMMITTED/ MOTIVATED TO THE GAME
that is the number 1 step.Also try to do a little research on the game and the systems, watch videos on how to take the system apart and back together.
I HAVE FAITH IN YOU!!!  YOU CAN DO IT!!! TAKE CHARGE

8 0
3 years ago
What are the two basic categories of film
kati45 [8]
Video and Sound are the 2 most basic categories of film
3 0
3 years ago
A(n) _______________ supplies one of the most critical aspects of docking stations, but in a smaller, more portable format: supp
baherus [9]

Answer:

A Port Replicators.

Explanation:

Port replicators are devices or extension. They are plugged into the laptop's usb port to provide extra ports to connect other external devices needed by the laptop.

Docking stations does the same thing, but the laptop is plugged into the docking station holding the needed devices, and meant for that laptop brand.

7 0
3 years ago
is skill in using productivity software, such as word processors, spreadsheets, database management systems, and presentation so
Digiron [165]

Answer:

It is general knowledge

Explanation:

What you covered is general knowledge and the entrance to computer science.

4 0
3 years ago
Write a program that prompts the user to enter a series of numbers between 0 and 10 asintegers. The user will enter all numbers
Anna71 [15]

Answer:

The program in Python is as follows:

import collections

from collections import Counter

from itertools import groupby

import statistics

str_input = input("Enter a series of numbers separated by space: ")

num_input = str_input.split(" ")

numList = []

for num in num_input:

         if(num.lstrip('-').isdigit()):

                   if num[0] == "-" or int(num)>10:

                             print(num," is out of bound - rejecting")

                   else:

                             print(num," is valid - accepting")

                             numList.append(int(num))

         else:

                   print(num," is not a number")

print("Largest number: ",max(numList))

print("Smallest number: ",min(numList))

print("Range: ",(max(numList) - min(numList)))

print("Mode: ",end = " ")

freqs = groupby(Counter(numList).most_common(), lambda x:x[1])

print([val for val,count in next(freqs)[1]])

count_freq = {}

count_freq = collections.Counter(numList)

for item in count_freq:

         print(item, end = " ")

         lent= int(count_freq[item])

         for i in range(lent):

                   print("#",end=" ")

print()

Explanation:

See attachment for program source file where comments are used as explanation. (Lines that begin with # are comments)

The frequency polygon is printed using #'s to represent the frequency of each list element

7 0
2 years ago
Other questions:
  • 1. When centering one paragraph on a page of text, the user needs to _____.
    15·2 answers
  • Write a MATLAB code which asks a user for an integer number and computes the factorial of that number. Use while loop to create
    11·1 answer
  • Which is most harmful computer virus define​
    15·1 answer
  • Keyboards and printers are two examples of _________ devices.
    6·1 answer
  • ANYBODY WANNA PLAY FoRnITe
    11·2 answers
  • What is the limitation of computer<br>​
    5·1 answer
  • PLEASE HELP!! WILL MARK BRAINLIEST!!
    15·1 answer
  • Select the correct answer.
    10·1 answer
  • What is your personal definition of life? How do you appreciate life?​
    10·1 answer
  • Refer to the exhibit. Host B on subnet Teachers transmits a packet to host D on subnet Students. Which Layer 2 and Layer 3 addre
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!