In: Computer Science
Pizza analysis, lab3pr1.py You noticed that the menu of your favorite pizza
chain store is rather complicated. They offer a range of pizza
size and price op-
tions, making it difficult to see what option offers the most pizza
for your dol-
lars. So you decide to write program that calculates the cost per
square inch
of a circular pizza, given its diameter and price, similar to
how grocery stores
display cost-per-ounce prices. The formula for area is A = r
2 ∗ π. Use two func-
tions: one called area(radius) to compute the area of a pizza, and
one called
cost per inch(diameter, price) to compute cost per square inch.
Sample runs
of your program should look like this:
Please enter the diameter of your pizza, in inches: 20
Please enter its cost, in dollars: 20
The cost is 0.06 dollars per square inch.
>>>>
Please enter the diameter of your pizza, in inches: 8.5
Please enter its cost, in dollars: 12.99
The cost is 0.23 dollars per square inch.
Use the built-in Python function round(value, 2) to round the
final cost-per-
inch value to two decimal points. Use import math and math.pi to
get the value
of pi for area computation.
use python
from math import pi
def area(radius):
return radius*radius*pi
def cost_per_inch(diameter, price):
radius = diameter/2;
A = area(radius)
cost = price/A;
return round(cost,2)
diameter = float(input("Please enter the diameter of your pizza,
in inches: "))
cost = float(input("Please enter its cost, in dollars: "))
print("The cost is {} dollar per square
inch.".format(cost_per_inch(diameter,cost)))