[Tutor] trouble with "if"

Grant Hagstrom grantahagstrom at gmail.com
Wed May 30 07:51:19 CEST 2007


Right above the empty reply box is a "reply to all" link. Hit it, and you're
good to go.

On 5/30/07, Adam Urbas <jped.aru at gmail.com> wrote:
>
> Dang it... I am really going to have to figure out how to reply all.
> The cc thing only worked once and now I'm still sending to you.
>
> On 5/30/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > I started to read Alan Gauld's tutorial.  The problem is, once I get
> > past the very basics of something, I tend to get impatient and don't
> > want to go back and have to redo them, but the other problem is, I may
> > need something that is taught in the basic sections.  So ya, I'll try
> > to keep on a reading Alan's tutorial.
> >
> > On 5/30/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > > I have already subscribed.  I tried sending a message when I was not
> > > yet subscribed, and the Moderator or Administrator, or whoever said to
> > > resubscribe.  Sorry about my accident programming.
> > >
> > > On 5/29/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > > > ok well, I'm testing to see if the CC thing worked.
> > > >
> > > > On 5/29/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > > > > I'll try the CC thing.
> > > > >
> > > > > On 5/29/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > > > > > Well, Brian, I am now very sure that we have different versions
> of
> > > > > > gmail, because on both the Quick Reply and the full reply
> screens,
> > > > > > there are no Reply buttons, or downpointing arrows.
> > > > > >
> > > > > > On 5/29/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > > > > > > What is the actual command to exit the program.  I tried exit,
> > which
> > > > > > > turned purple, so I know that does something.
> > > > > > >
> > > > > > > On 5/29/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > > > > > > > No I don't think that worked either, because now it has a
> > problem
> > > > with
> > > > > > > > print.
> > > > > > > >
> > > > > > > > Please help.
> > > > > > > >
> > > > > > > > Au
> > > > > > > >
> > > > > > > > On 5/29/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > > > > > > > > I'm having trouble with the parentheses after the def
> thing().
> > > > IDLE
> > > > > > > > > says that there is something wrong with it.  If I type
> > something
> > > > > > > > > between them, it says that there is something wrong with
> the
> > > > > quotation
> > > > > > > > > marks.  If I just leave it like (), then it says that
> > something
> > > is
> > > > > > > > > wrong with what is after the parentheses.  Unless my code
> is
> > > > > supposed
> > > > > > > > > to go between the parentheses.  I'll try that.
> > > > > > > > >
> > > > > > > > > On 5/29/07, Adam Urbas <jped.aru at gmail.com> wrote:
> > > > > > > > > > In the def welcome(), what do you put in the
> parentheses?
> > > > Another
> > > > > > > > > > question, what code do you use for ending the
> program.  I
> > want
> > > > the
> > > > > > > > > > user to be able to cancel the program from the main
> menu,
> > > where
> > > > it
> > > > > > > > > > asks you to choose circle, square, etc.  Or even perhaps
> > allow
> > > > the
> > > > > > > > > > user to go back to a previous menu, well I suppose that
> > would
> > > be
> > > > > the
> > > > > > > > > > def thing() code.  But what if they were at the part
> where
> > the
> > > > > > program
> > > > > > > > > > was asking them to input the radius, how would I give
> them
> > the
> > > > > > option
> > > > > > > > > > of returning to the list of given measurements of a
> circle?
> > > > > > > > > >
> > > > > > > > > > On 5/29/07, Brian van den Broek <broek at cc.umanitoba.ca>
> > wrote:
> > > > > > > > > > > adam urbas said unto the world upon 05/29/2007 12:39
> PM:
> > > > > > > > > > > > The scary part is, I think I understand this.  I
> copied
> > > your
> > > > > > last
> > > > > > > > > > > > example and put it in IDLE and it doesn't like you
> code.
> > > > > Never
> > > > > > > > > > > > mind.  I figured it out.  So that is so it will
> notify
> > you
> > > > if
> > > > > > your
> > > > > > > > > > > > choice is invalid.  Nice lil tidbit of information
> > there.
> > > > > I'll
> > > > > > be
> > > > > > > > > > > > sure to use this.  Oh and while your here, I'd like
> to
> > ask
> > > > > about
> > > > > > > > > > > > loops I guess they are.  I want to have the program
> go
> > > back
> > > > to
> > > > > > the
> > > > > > > > > > > > part where it asks for the user to select an option
> > after
> > > it
> > > > > has
> > > > > > > > > > > > run one of its if statements.Like, when the user
> tells
> > it,
> > > > > > > > > > > > "circle," then "radius," then enters the radius:
> here I
> > > > would
> > > > > > like
> > > > > > > > > > > > the program to go back and ask the user if they want
> to
> > do
> > > > > > > anything
> > > > > > > > > > > > else, like find the area of a square, instead of the
> > > circle.
> > > > > > > Would
> > > > > > > > > > > > I have to tell python to print all those selections
> > again,
> > > > or
> > > > > > > would
> > > > > > > > > > > > there be a way to just return to the
> > beginning?Thanks,Au>
> > > > > Date:
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Hi Adam,
> > > > > > > > > > >
> > > > > > > > > > > Again, I cut the mess, but I expect that if you use
> the
> > > gmail
> > > > > > > account
> > > > > > > > > > > you just posted about here on in, that will be the end
> of
> > > it.
> > > > > > > > > > >
> > > > > > > > > > > I'm glad that you are starting to have the warm glow
> of
> > > > > > > understanding
> > > > > > > > > :-)
> > > > > > > > > > >
> > > > > > > > > > > What you are asking about here is one reason why
> functions
> > > are
> > > > > so
> > > > > > > > > > > useful. They allow you (more or less) to give a name
> to a
> > > > chunk
> > > > > of
> > > > > > > > > > > code, and then you can rerun that chunk at will by
> > invoking
> > > > the
> > > > > > > name.
> > > > > > > > > > >
> > > > > > > > > > > Given the problem you want to solve, I'd structure my
> code
> > > > > > something
> > > > > > > > > > > like the following. Most of the details need to be
> filled
> > > in,
> > > > > but
> > > > > > > this
> > > > > > > > > > > is the skeletal structure.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > def welcome_message():
> > > > > > > > > > >      # Some actions to invoke when the user starts the
> > > program
> > > > > > > > > > >      print "Welcome to this program."
> > > > > > > > > > >
> > > > > > > > > > > def display_menu():
> > > > > > > > > > >      # Insert code for showing the user the menu of
> > options
> > > > > > > > > > >      pass
> > > > > > > > > > >
> > > > > > > > > > > def circle_area():
> > > > > > > > > > >      # insert code here to ask user for the radius,
> > compute
> > > > the
> > > > > > > area,
> > > > > > > > > > >      # and display the result. You might well want to
> > divide
> > > > > that
> > > > > > up
> > > > > > > > > > >      # into other functions that this one calls.
> > > > > > > > > > >      pass
> > > > > > > > > > >
> > > > > > > > > > > def square_area():
> > > > > > > > > > >      # Likewise
> > > > > > > > > > >      pass
> > > > > > > > > > >
> > > > > > > > > > > # And so on, for each shape that you wish to handle
> > > > > > > > > > >
> > > > > > > > > > > def exit_message():
> > > > > > > > > > >      # Some actions to invoke when the user chooses to
> > > > terminate
> > > > > > > > > > >      # the program.
> > > > > > > > > > >      print "Thank you for using this program.
> Goodbye."
> > > > > > > > > > >
> > > > > > > > > > > def prompt_user():
> > > > > > > > > > >      # Here is where the sort of code I showed you
> before
> > > > would
> > > > > > go.
> > > > > > > > > > >      # I'd include an option, say 0, for exiting,
> which,
> > > when
> > > > > the
> > > > > > > > > > >      # user picks it, you call exit_message()
> > > > > > > > > > >
> > > > > > > > > > >      while True:
> > > > > > > > > > >          try:
> > > > > > > > > > >              choice = int(raw_input("Please make your
> > choice
> > > > "))
> > > > > > > > > > >              if choice < 0 or choice > 2: # Adjust to
> suit
> > > > > options
> > > > > > > > > > >                  raise ValueError
> > > > > > > > > > >              break
> > > > > > > > > > >          except ValueError:
> > > > > > > > > > >              print "Please make a choice from the
> options
> > > > > > offered."
> > > > > > > > > > >
> > > > > > > > > > >      # sends the choice back to the code that called
> > > > prompt_user
> > > > > > > > > > >      # We won't get here until a good choice has been
> made
> > > > > > > > > > >      return choice
> > > > > > > > > > >
> > > > > > > > > > > def main():
> > > > > > > > > > >      # The main function driving your program. It
> might
> > look
> > > > > > > > > > >      # something like this:
> > > > > > > > > > >      welcome_message()
> > > > > > > > > > >
> > > > > > > > > > >      while True:   # This will loop forever until you
> > break
> > > > out
> > > > > > > > > > >          display_menu()
> > > > > > > > > > >          choice = prompt_user()
> > > > > > > > > > >
> > > > > > > > > > >          if choice == 0:
> > > > > > > > > > >              exit_message()
> > > > > > > > > > >              break   # Terminate the while loop
> > > > > > > > > > >          elif choice == 1:  # Assuming 1 was the
> option
> > for
> > > > > circle
> > > > > > > > > > >              circle_area()
> > > > > > > > > > >          elif choice == 2:
> > > > > > > > > > >              square_area()
> > > > > > > > > > >          # And so on
> > > > > > > > > > >
> > > > > > > > > > >          print "Please make another choice:"   # Go
> back
> > to
> > > > top
> > > > > of
> > > > > > > > loop
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > if __name__ == '__main__':
> > > > > > > > > > >      # This will run if you run the script, but not if
> you
> > > > > import
> > > > > > > it.
> > > > > > > > > > >      main()
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > This has not been tested (it is only an outline) but
> it
> > does
> > > > > pass
> > > > > > > the
> > > > > > > > > > > only so reliable eyeball check :-)
> > > > > > > > > > >
> > > > > > > > > > > I'd suggest you try filling this sketch out to be
> useful,
> > > and
> > > > > post
> > > > > > > if
> > > > > > > > > > > you run into troubles.
> > > > > > > > > > >
> > > > > > > > > > > Best,
> > > > > > > > > > >
> > > > > > > > > > > Brian vdB
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070530/adf5b0da/attachment-0001.html 


More information about the Tutor mailing list