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

Adam Urbas jped.aru at gmail.com
Wed May 30 20:59:02 CEST 2007


Once again this is my latest version.  I know of several problems,
such as the previously posted infinite looping problem.  Also, if
sends you to the wrong place sometimes.  Ex:  a second ago, I pressed
4 to exit (which does not work either) and it took me to triangle.
I'm not sure how to end the program.  It takes you to the def
goodbye(): part, but then if you press enter again, it starts the
program over.  I was hoping that if I just left it blank, then it
would just automatically end, like it does with simpler programs, but
that was not the case, because apparently there has to be something
after the
def goodbye():
So If someone wouldn't mind taking a look at it, then I would be very grateful.

Thanks,
Au

On 5/30/07, Adam Urbas <jped.aru at gmail.com> wrote:
> 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 --------------
An embedded and charset-unspecified text was scrubbed...
Name: acp.py
Url: http://mail.python.org/pipermail/tutor/attachments/20070530/d1999cbd/attachment.pot 


More information about the Tutor mailing list