Complete Question:
Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store. Console Price Comparison Price of 64 oz size: 5.99 Price of 32 oz size: 3.50 Price per oz (64 oz): 0.09 Price per oz (32 oz): 0.11
Using Python
Answer:
<em>This program does not make use of comments (See explanation section)</em>
price64 = float(input("Price of 64 oz size: "))
price32 = float(input("Price of 32 oz size: "))
unit64 = price64/64
unit32 = price32/32
print("Unit price of 64 oz size: ", round(unit64,2))
print("Unit price of 32 oz size: ", round(unit32,2))
if unit64>unit32:
print("Unit price of 64 oz is greater" )
else:
print("Unit price of 32 oz is greater" )
Explanation:
This line prompts the user for the price of 64 oz size
price64 = float(input("Price of 64 oz size: "))
This line prompts the user for the price of 32 oz size
price32 = float(input("Price of 32 oz size: "))
This line calculates the unit price of 64 oz size
unit64 = price64/64
This line calculates the unit price of 32 oz size
unit32 = price32/32
This next two lines print the unit prices of both sizes
print("Unit price of 64 oz size: ", round(unit64,2))
print("Unit price of 32 oz size: ", round(unit32,2))
The next line compares the unit prices of both sizes
if unit64>unit32:
This line is executed if the unit price of 64 oz is greater than 32 oz
print("Unit price of 64 oz is greater" )
else:
This line is executed, if otherwise
print("Unit price of 32 oz is greater" )