Hey there, I've never actually used a forum to ask for help on any sort of project before, but I'm a little stuck.. okay, a lot. =D It's probably something really stupid and minuscule, though. Anyway, heres the project.. I hope it's not too confusing:


Write a program that asks the user for the diameter and the cost of a pizza.

Use a function (getInputs()) to get the diameter and cost of the pizza and return the two values.

Use a function (calcArea(diameter)) to calculate the area of the pizza in square inches.

Use a function (calcCostPerSqInch(area, cost)) to calculate the area of a pizza in square inches.

Use a function (printResults(diameter, cost, area, perSq)) to print the results.


Annnnd, here's what I have so far...:

import math 

def main():
    
    intro()

    diameter, cost = getInputs()

    calcArea(diameter)

    calcCostPerSqInch(area, cost)

    printResults(diameter, cost, area, perSq)

def getInputs():
    #prompt for the diameter and cost from the user
    diameter = input("Enter the diameter (in inches): ")
    print
    print
    cost = input("Enter the cost (in dollars): ")
    print
    print
    return diameter, cost

#create calcArea function
def calcArea(diameter):
    area = math.pi * (diameter / 2) ** 2
    
#create calcCostPerSqInch function
def calcCostPerSqInch(area, cost):
    perSq = area / cost

#create printResults function
def printResults(): 
    print "For a diameter of ", diameter," inches"
    print "and a cost of $", cost,":"
    print "Area in square inches: ",  area
    print "Cost per square inch:     $", perSq

def intro():
    #print explination to the user
    print "Program to calculate the area and cost"
    print "per square inch of a pizza."
    print "You will be asked to enter the diameter"
    print "of the pizza in inches and the cost in dollars."
    print
    
main()

Thanks in advance!!

I dont know why you marked it solved,but write some abought the problem you have.

So think you got a assignment about Top-Down Design.
You are on the right path.

Top-Down Design u call main and you work your way down one function/problem at the time.

Gone show how to break this opp.
The you see problem more clearer.

Part 1

import math 

def main():    
    intro()             
    
def intro():
    #print explination to the user
    print "Program to calculate the area and cost"
    print "per square inch of a pizza."
    print "You will be asked to enter the diameter"
    print "of the pizza in inches and the cost in dollars."
    print  

main()

First part we just test the the intro() function.
Work fine.

Part 2 we test getInputs() and that it print correct(printResults())

#!/usr/bin/env python
import math
def main():    
    intro()     
    diameter, cost = getInputs()     
    printResults(diameter, cost)         
    
def intro():
    #print explination to the user
    print "Program to calculate the area and cost"
    print "per square inch of a pizza."
    print "You will be asked to enter the diameter"
    print "of the pizza in inches and the cost in dollars."
    print  

def getInputs():
    #prompt for the diameter and cost from the user
    diameter = input("Enter the diameter (in inches): ")
    print
    print
    cost = input("Enter the cost (in dollars): ")
    print
    print
    return diameter, cost   

#create printResults function
def printResults(diameter, cost):
   
    print "For a diameter of ",diameter ," inches"
    print "and a cost of $", cost,":" 

main()
'''output-->
You will be asked to enter the diameter
of the pizza in inches and the cost in dollars.

Enter the diameter (in inches): 5

Enter the cost (in dollars): 30

For a diameter of  5  inches
and a cost of $ 30 :
'''

So part 2 is working

Part 3 here was you problem.
With calling of function calcArea() and calcCostPerSqInch()
I removed this 2 lines.
calcArea(diameter)
calcCostPerSqInch(area, cost)

And put the call of calcArea(diameter) in the printResults() function
you see put the call of calcCostPerSqInch() here
print "Cost per square inch is %.2f" % (calcCostPerSqInch(area, cost))

So the final part

#!/usr/bin/env python
import math 

def main():    
    intro()    
    diameter, cost = getInputs()    
    printResults(diameter, cost, calcArea(diameter))  
    
def intro():
    #print explination to the user
    print "Program to calculate the area and cost"
    print "per square inch of a pizza."
    print "You will be asked to enter the diameter"
    print "of the pizza in inches and the cost in dollars."
    print 

def getInputs():
    #prompt for the diameter and cost from the user
    diameter = input("Enter the diameter (in inches): ")
    print
    print
    cost = input("Enter the cost (in dollars): ")
    print
    print
    return diameter, cost

#create calcArea function
def calcArea(diameter):
    area = math.pi * (diameter / 2) ** 2
    return area
    
#create calcCostPerSqInch function
def calcCostPerSqInch(area, cost):
    perSq = area / cost
    return perSq    

#create printResults function
def printResults(diameter, cost, area):
   
    print "For a diameter of",diameter,"inches"
    print "and a cost of $", cost,":"
    print "Area in square inches is %.2f" % (area)
    print "Cost per square inch is %.2f" %  (calcCostPerSqInch(area, cost))
    
main()
'''output-->
Program to calculate the area and cost
per square inch of a pizza.
You will be asked to enter the diameter
of the pizza in inches and the cost in dollars.

Enter the diameter (in inches): 5

Enter the cost (in dollars): 30

For a diameter of 5 inches
and a cost of $ 30 :
Area in square inches is 12.57
Cost per square inch is 0.42
'''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.