[Tutor] (no subject)
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Tue, 28 Aug 2001 21:53:07 -0700 (PDT)
On Tue, 28 Aug 2001, melvin2001 wrote:
> ahhh i thought dman was the only one that was gonna respond for awile
> so i guess i'll just post a follow up like this (even though i already
[some code cut]
In your circle_area() function:
###
def circle_area():
print "would you like to input radius or diameter?"
print "1. radius"
print "2. diameter"
question = input ("> ")
if question == 1:
print "what is the radius?"
radius = input("> ")
radius = 3.14*radius**2
print radius
elif question == 2:
print "what is the diameter?"
diameter = input ("> ")
diameter = diameter/2
diameter = diameter**2 * 3.14
print diameter
###
in the second case, since you're dividing the diameter by 2, it's
perfectly ok to call that result the radius.
###
# ...
elif question == 2:
print "what is the diameter?"
diameter = input ("> ")
radius = diameter/2
area = radius**2 * 3.14
print area
###
Likewise, we can call the thing that holds the area the variable name:
"area". You don't need to reuse "diameter" as a variable if it no longer
represents the diameter. Electrons are still in abundant supply, despite
the power crisis here. *grin* In short: it's perfectly ok to be a little
indulgent with variable names if we're in a function.
> i commented out a few of the options because i didn't want to take the
> time to define them yet and i'm gonna add a menu option for exit next
> :-) and im gonna try that little menu thing thanks to ignacio.....you
> guys are great thanks for the help lol i'll be sure to ask you guys
> lots of questions
Your code looks good. Keep the questions coming!