473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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_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()
Mar 28 '06 #1
1 1863
# 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
Aug 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
0
by: Dale McGorman | last post by:
The following is some code that I am trying to bring over from VB 6.0, that I have working there. I am trying to get to where I can talk to a USB device. I am stuck on how to correctly pass params...
4
by: Markus Brenner | last post by:
Hi there! Hope anybody can help. I want to at least read (maybe write) the extended file properties of office documents like winword, excel, .... I've tried two ways till now, one by opening...
1
by: csgraham74 | last post by:
Hi there, ive written a function to display some returned values in a table. I use response.write to write the values as html. My problem is that this has stopped working correctly and i find...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
6
by: DL | last post by:
Hi I have an array of objects: Student studentarray; how do I save studentarray to file? David.
24
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone...
3
by: Ben Keshet | last post by:
I have a probably simple beginner's question - I have a script that I am currently able to print its output. instead, i want to write it into a file - I tried different versions of write() but...
16
by: AAaron123 | last post by:
I have a timer. At each tick, say 0.1 second, I write a file. If it takes more than 0.1 second to write the file the app will not work correctly. How can I tell in the tick event if the...
4
by: -Lost | last post by:
How should one write a plug-in interface? I've tossed around several ideas but rudimentary ones at best. For example: Plug-In-A -Plug-In-Proxy -Application The plug-in simply hands off its...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.