[Tutor] [Fwd: Re: trouble with "if"]

Adam Urbas jped.aru at gmail.com
Wed May 30 19:49:42 CEST 2007


Ok I forgot to put some things on the previous one.  I discovered a
flaw in my loop.  It is not infinite.  If you select circle, radius,
enter the radius, circle, radius, enter the radius, then the program
stops.  I want it to be able to keep going as many times as needed,
infinitely.  So that the user could keep using that segment of the
program over and over again, without having to restart the program.
Is it possible to do that?

On 5/30/07, Adam Urbas <jped.aru at gmail.com> wrote:
> I think I may have figured it out.  I just switched some things around.
>
> On 5/30/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > I can't seem to get the type with the parameters to work.  I can get
> > def answer(): to work, but not def
> > answer(my_first_parameter,my_second_parameter):.  I'm not too
> > concerned, as I haven't yet needed to use that.  But, when I use the
> > parameter type, it runs without error messages, but doesn't display
> > anything.  That's when I'm using your example with my_first_parameter.
> >  But when I use:
> >
> > def answer(40,2):
> >     answer=40+2
> >     print "Answer:\t", value
> > answer()
> >
> > it says:
> >
> > There's an error in your program:
> > invalid syntax
> >
> > and then it highlights the first number between the parentheses, like last time.
> >
> > OK. New topic temporarily... I just completed a portion of my
> > radiacir.py program, after much debugging.  I still want to add that
> > error message thing that we discussed eariler, but that's a whole
> > nother can of worms.  So I'm going to attach it.  This is very
> > exciting.  Except, I renamed it and now it doesn't work.  This
> > frustrates me.  How could something work one second and then not the
> > next.  Oh well, I'll still attach it and if you could help me find the
> > problem, that would be nice.
> >
> > Thanks,
> > Au
> > On 5/30/07, Brian van den Broek <broek at cc.umanitoba.ca> wrote:
> > > Adam Urbas said unto the world upon 05/30/2007 11:01 AM:
> > > > I can't exactly show you the error message anymore, because the program is
> > > > now screwed up in so many ways that I can't even get it to do the things it
> > > > used to.
> > > >
> > > > It says things like ERROR: Inconsistent indentation detected!
> > > > 1) Your indentation is outright incorrect (easy to fix), OR
> > > > 2) Your indentation mixes tabs and spaces.  Then it tells me to untabify
> > > > everything, which i did and it still gives this message.  I've started
> > > > completely over with the exact same indentation and that one works.
> > > >
> > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was
> > > > here
> > > > last night.  I have no idea what was going on then, but everything you guys
> > > > said is right here.  The plain text is right next to the Check spelling,
> > > > the
> > > > reply to all is right above send and save now and in the corner near the
> > > > little arrow.  Well, it's working now.
> > > >
> > > > Ok, so if i have a section of code that is:
> > > >
> > > > answer=(2+3):
> > > > print "answer", answer
> > > >
> > > > so for the code above I would put: (I think I would have to have the two
> > > > numbers and the addition thing in there wouldn't I; I saw something like
> > > > this on Alan's tutorial last night.)
> > > >
> > > > def answer(2,3):
> > > >    answer=(2+3)
> > > >    print "answer",answer
> > > >
> > > > That is obviously not right.:
> > > >
> > > > There's an error in your program:
> > > > invalid syntax
> > > >
> > > > when it says that it highlights the 2: def answer(2+3):
> > > >
> > > > Ok I think I understand these now.  Thanks for the advice.  I have this
> > > > now:
> > > >
> > > > def answer():
> > > >    print("answer")
> > > > answer()
> > > >
> > > > It works too, yay!
> > > > Thanks,
> > > >
> > > > Au
> > > >
> > >
> > >
> > > Adam,
> > >
> > > Glad you are sorting out the gmail---in the long run, plain text will
> > > make this all much easier than what you had before :-)
> > >
> > > Your answer function definition above is saying something like this:
> > > make answer the name of a function that takes no parameters, and, when
> > > called, have it execute a print.
> > >
> > > This:
> > >
> > >  > def answer(2,3):
> > >  >    answer=(2+3)
> > >  >    print "answer",answer
> > >
> > > doesn't work, as you are trying to set the values of the two
> > > parameters to 2 and 3 in the function definition itself. That's not
> > > how parameters work. The definition of a function sets the parameters
> > > up as named `slots' that function calls will give values to. (There
> > > are, as Andre pointed out, more details, but let those aside for now
> > > and focus on the simplest cases.)
> > >
> > > This:
> > >
> > > def answer():
> > >      answer=(2+3)
> > >      print "answer",answer
> > >
> > > would work, but it isn't much different than the code that did work.
> > >
> > > Try this:
> > >
> > > def answer(my_first_parameter, my_second_parameter):
> > >      value = my_first_parameter + my_second_parameter
> > >      print "Answer:\t", value
> > >
> > > (I wouldn't use the cumbersome names `my_first_parameter', etc. in
> > > real code, but perhaps they help keeping track of what is going on in
> > > early stages.)
> > >
> > > That says, in effect, let answer be a function which takes two
> > > positional parameters, adds them, and prints the result in an
> > > informative way.
> > >
> > >  >>> answer(40, 2)
> > > Answer: 42
> > >  >>> answer("A string", " and another string")
> > > Answer: A string and another string
> > >  >>>
> > >
> > > These work because the function definition ensures that the first
> > > parameter (40, in the first case above) will, as far as the function
> > > is concerned, be called my_first_parameter. (Likewise for 2 and
> > > my_second_parameter.)
> > >
> > > Does that help?
> > >
> > > Brian vdB
> > >
> >
>
>
-------------- next part --------------
#Welcome screen:
def welcome():
    print "Welcome to the Area Calculation Program."
    print
welcome()

#Shape choice:
def shape():
    print "Choose a Shape:"
    print "1 Circle"
    print "2 Square"
    print "3 Triangle"
    print "4 Exit"
    print
shape()

#If circle:
def circle():
    shape=raw_input(">")
    if shape in["1","circle"]:
        print "1 Radius"
        print "2 Diameter"
        print "3 Circumference"
        print "4 Area"
        print

circle()


#If radius:
def radius():
    radius=int(raw_input("Enter Radius:"))
    diameter=(radius*2)
    circumference=(diameter*3.14)
    area=(radius**2*3.14)
    print "Diameter",diameter
    print "Circumference",circumference
    print "Area",area
    print
    print


def choice():
    given=raw_input(">")
    if given in["1","radius"]:
        radius()
choice()

shape()
choice()


More information about the Tutor mailing list