# tpm.py Computes the cost per square inch of pizza given cost of the pizza,
# and diameter.
from math import *
def main():
cost_per_square_inch(area_of_pizza())
def area_of_pizza():
diameter = input("Enter the diameter of the pizza: ")
radius = 1.0/2.0 * diameter
a = pi * radius * radius
return a
def cost_per_square_inch(area):
cost_of_pizza = input("Enter the cost of the pizza: ")
cost = cost_of_pizza/area
print "The cost per square inch of pizza is $%0.2f"%(cost)
return
main()
Probably out of date, but anyway: the program sure is written correctly. And there are about a bazillion other ways of writing it, but de algorithm would stay de same.
For instace:
>from math import *
>
>def area_of_pizza():
> diameter = input("Enter the diameter of the pizza: ")
> radius = 1.0/2.0 * diameter
> a = pi * (radius ** 2) # ** is to the power of sth.
> return a
>
>def cost_per_square_inch(area):
> cost_of_pizza = float(raw_input("Enter the cost of the pizza: "))
> # u can also write that instead of just input, doesn't really change much >though
> cost = cost_of_pizza/area
> print "The cost per square inch of pizza is $%0.2f"%(cost)
>
>area=area_of_pizza()
>cost_per_square_inch(area)
~Mo