# 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: ")
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()

:?: :o

## All 2 Replies

Please wrap you code in code tags, see:
http://www.daniweb.com/techtalkforums/announcement114-3.html

This way the proper indentations are added.

I would not pass function on as argument, so rewrite you code:

``````from math import *  # to get pi

def main():
# first get the area of the whole pizza
area = area_of_pizza()
cost_per_square_inch(area)

def area_of_pizza():
diameter = input("Enter the diameter of the pizza: ")
return a

def cost_per_square_inch(area):
# get the cost of the whole pizza
cost_of_pizza = input("Enter the cost of the pizza: ")
# calculate the cost per area unit
cost = cost_of_pizza/area
print "The cost per square inch of pizza is \$%0.2f" % (cost)

main()``````

Since you only need math.pi you don't have to import all math functions/constants. You could use:

``from math import pi``

Remember one of the basic rules of computing, ideally the flow in a program should be:

get data

process data

show result

After I said this, I got interested myself to write the flow, here is my overblown code:

``````# find cost of a square inch of pizza given cost and size/diameter
# a small program to show flow of data via functions

def main():
# get data
cost = get_cost()
size = get_size()
# process data
area = calc_area(size)
cost_sqinch = cost_per_area(cost, area)
# present result
show_result(cost_sqinch)

def get_cost():
# avoid using input(), raw_input() gets a string, so convert to float
return float(raw_input("Enter the cost of the pizza: "))

def get_size():
# again, avoid using input()
return float(raw_input("Enter the diameter of the pizza: "))

def calc_area(diameter):
"""calculate the area of a circle"""
pi = 3.1416  # good enough