Did I write this correctly, and is there other ways to write it?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • butterflyTee
    New Member
    • Mar 2006
    • 4

    Did I write this correctly, and is there other ways to write it?

    # 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_p izza())

    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()
  • Moritz B
    New Member
    • Aug 2006
    • 6

    #2
    Originally posted by butterflyTee
    # 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_p izza())

    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_p izza()
    >cost_per_squar e_inch(area)

    ~Mo

    Comment

    Working...