[Tutor] a question about passing values between functions
kristinn didriksson
kdidriksson at yahoo.com
Fri Nov 17 19:05:02 CET 2006
Hello,
I am still wrestling with the concept of values going
between functions. (just starting out)The program
below works seems to work, but here is my question.
In my understanding, return area in the first routine
makes the value of area an instance of areaCirc and I
use areaCirc in the other program to call the value
for the area that was calculated in the first routine.
Is that the right way to think of this program? Did I
use return area correctly?
This is a new vocabulary, so I hope I am making sense.
Basically, I am wondering if I needed to use the
return area statement.
Thanks,
Kristinn
---------------
# this program is a redo of ex2 ch3 with a
twist!
2 # use two functions--one to compute the area
of a pizza, and one to
3 # to compute cost per square inch.
4 # Given are the diameter and the price. A =
pi(r**2)
5
6 # define the function that computes the area
7 import math
8 def areaCirc():
9 diameter = input("Please input the
diameter of the pizza: ")
10 area = 4*(math.pi)*(diameter/2)**2
11 print "The area of the pizza is %0.2f" %
(area)
12 return area
13
14
15 def unitCost():
16 price = input("Please input the cost of
the pizza per square inch: ")
17 area = areaCirc()
18 cost = area * price
19 print "The cost of the pizza is %0.2f"
%(cost)
20
21 unitCost()
---------------------------
____________________________________________________________________________________
Sponsored Link
Compare mortgage rates for today.
Get up to 5 free quotes.
Www2.nextag.com
More information about the Tutor
mailing list