[Tutor] trouble with "if"

adam urbas adamurbas at hotmail.com
Wed May 23 19:04:10 CEST 2007


Sorry, I don't think Hotmail has turn off HTML.  If it does I havn't been able to find it.  I think you're going to have to explain your little bit of text stuff down there at the bottom.  I have no idea what most of that means.  All my choice things are working now though.  I think that is what you were trying to help me with.  What I used wasif shape in["1","circle"]:and if shape == "1" or shape =="circle":It works perfectly fine now.Ya that little bit o' code is really puzzling.  I wish I knew more about this python deal.  I understand the concept, but not the rules or the techniques and things of that sort.  OK... I've got it... the data=raw_input('Feed Me!').  Ok I now understand that bit.  Then it says Feed Me!  and you put 42 (the ultimate answer to life the universe, everything).  OK, it won't accept the <type 'str'> bit.  it doesn't like the "<".  Well, I just removed that bit and it said:Feed Me!  and I put 42, and it said >>> (I guess it's satisfied now, with the whole feeding).  Well if I understood what 'str' meant, then I could probably figure the rest out.  Well I have to go do other things so I'll save the rest of this figuring out till later.I shall return,Adam> Date: Wed, 23 May 2007 12:12:16 -0400> From: broek at cc.umanitoba.ca> To: adamurbas at hotmail.com> CC: tutor at python.org> Subject: Re: [Tutor] trouble with "if"> > adam urbas said unto the world upon 05/23/2007 11:57 AM:> > > > Hi all,> > > > I've been working with this new program that I wrote.  I started out > > with it on a Ti-83, which is much easier to program than python.  Now > > I'm trying to transfer the program to python but its proving to be quite > > difficult.  I'm not sure what the whole indentation thing is for.  And > > now I'm having trouble with the if statement things. > > > > #"Circle Data Calculation Program:"> > print "Welcome to the Circle Data Calcuation Program."> > print> > > >     #"Menu 1:"> > print "Pick a shape:"> > print "(NOTE: You must select the number of the shape and not the shape > > itself)"> > print "1 Circle"> > print "2 Square"> > print "3 Triangle"> > > >     #"User's Choice:"> > shape=raw_input("> ")> > > >         #"Select Given:"> > if shape == 1:> >         print "Choose the given value:"> >         print "1 radius"> >         print "2 diameter"> >         print "3 circumference"> >         print "4 area"> > > > #"User's Choice:"> > given=raw_input("> ")> > > > if given == 1:> >         radius=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> > > > if given == 2:> >         diameter=raw_input("Enter Diameter:")> >         radius=(diameter/2)> >         circumference=(diameter*3.14)> >         area=(radius**2*3.14)> >         print "Radius:", radius> >         print "Circumference:", circumference> >         print "Area:", area> > > > if given == 3:> >         circumference=raw_input("Enter Circumference:")> >         radius=(circumference/3.14/2)> >         diameter=(radius*2)> >         area=(radius**2*3.14)> >         print "Radius:", radius> >         print "Diameter:", diameter> >         print "Area:", area> > > > if given == 4:> >         area=raw_input("Enter Area:")> >         radius=(area/3.14)> >          > > This is the whole program so far, because I haven't quite finished it > > yet.  But I tried to get it to display another list of options after you > > select a shape but it just does this.> > > > Pick a shape:> > 1 Circle> > 2 Square> > 3 Triangle> >  >1> >  >1> >  >>>> > > > I'm not sure why it does that but I do know that it is skipping the > > second list of options.> > > > Another of my problems is that I can't figure out how to get it to > > accept two different inputs for a selection.  Like I want it to accept > > both the number 1 and circle as circle then list the options for > > circle.  It won't even accept words.  I can only get it to accept > > numbers.  It's quite frustrating actually.> > > > Any advice would be greatly appreciated.> > Thanks in advance,> > Adam> > > > > > > Adam,> > Could you send plain text email rather than html, please? At least for > me, your code's indentation is all messed up unless I take some steps > to rectify it.> > The problem is that raw_input returns a string, and you are testing > whether given is equal to integers. See if this helps make things clear:> >  >>> data = raw_input('Feed me!')> Feed me!42>  >>> type(data)> <type 'str'>>  >>> data == 42> False>  >>> int(data) == 42> True>  >>>> > Best,> > Brian vdB
_________________________________________________________________
Change is good. See what’s different about Windows Live Hotmail. 
http://www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=RMT_TAGLM_HMWL_reten_changegood_0507
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070523/c42b07e3/attachment.htm 


More information about the Tutor mailing list