DEV Community

Cover image for Pizza Cost Per Inch Calculator
Scott Gordon
Scott Gordon

Posted on

Pizza Cost Per Inch Calculator

# pizza_cpi_calc.py
#   This program calculates the cost per square inch of a circular pizza,
#   given its diameter and price. The formula for area is A = Pi X radius^2.
# by: Scott Gordon

import math


# Create a function to calculate the area of a pizza.
def area_of_pizza(radius):
    area = math.pi * radius**2
    return area


# Create a function to calculate the cost per square inch of a pizza.
def cost_psi_pizza(price, diameter):
    radius = diameter / 2
    pizza_area = area_of_pizza(radius)
    cost_psi = price / pizza_area
    return cost_psi


# Run both functions to demonstate their output
def main():
    # Get user input for pizza diameter and price.
    pizza_diameter = int(
        input("What is the diameter of your pizza in inches? "))
    pizza_price = float(input("How much did the pizza cost? "))
    print(
        f"Your cost per square inch of your pizza is ${cost_psi_pizza(pizza_price, pizza_diameter):.2f}")


main()
Enter fullscreen mode Exit fullscreen mode

Photo by Ivan Torres on Unsplash

Oldest comments (2)

Collapse
 
mccurcio profile image
Matt Curcio

For me the question becomes is there a correlation between price per in^2 and quality or taste? lol

Collapse
 
shikkaba profile image
Me

Ah, but the price is already given to the pizza, and if you see the list of ingredients and an image of it, then your question may be answered?

Oh. My. God. I need to make a review website now. Since not all larges are the same size, you'll see how much you're paying per, and see the ingredients, and a picture, and see reviews... Gaaaaaaah someone's going to do this first now.