[Tutor] a question about passing values between functions
kdidriksson at yahoo.com
Fri Nov 17 19:05:02 CET 2006
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.
# this program is a redo of ex2 ch3 with a
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 =
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" %
12 return area
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"
Compare mortgage rates for today.
Get up to 5 free quotes.
More information about the Tutor