<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body><div style="text-align: left;">Thank you for the help Brian.&nbsp; I would like to ask you about these things.&nbsp; Which one of the examples you gave would be most fool proof.<br></div><br><br><br><hr id="stopSpelling">&gt; Date: Wed, 23 May 2007 13:40:09 -0400<br>&gt; From: broek@cc.umanitoba.ca<br>&gt; To: adamurbas@hotmail.com<br>&gt; CC: tutor@python.org<br>&gt; Subject: Re: [Tutor] trouble with "if"<br>&gt; <br>&gt; adam urbas said unto the world upon 05/23/2007 01:04 PM:<br>&gt; &gt; Sorry, I don't think Hotmail has turn off HTML.  If it does I<br>&gt; &gt; havn't been able to find it.  I think you're going to have to<br>&gt; &gt; explain your little bit of text stuff down there at the bottom.  I<br>&gt; &gt; have no idea what most of that means.  All my choice things are<br>&gt; &gt; working now though.  I think that is what you were trying to help<br>&gt; &gt; me with.  What I used wasif shape in["1","circle"]:and if shape ==<br>&gt; &gt; "1" or shape =="circle":It works perfectly fine now.Ya that little<br>&gt; &gt; bit o' code is really puzzling.  I wish I knew more about this<br>&gt; &gt; python deal.  I understand the concept, but not the rules or the<br>&gt; &gt; techniques and things of that sort.  OK... I've got it... the<br>&gt; &gt; data=raw_input('Feed Me!').  Ok I now understand that bit.  Then it<br>&gt; &gt; says Feed Me!  and you put 42 (the ultimate answer to life the<br>&gt; &gt; universe, everything).  OK, it won't accept the &lt;type 'str'&gt; bit.<br>&gt; &gt; it doesn't like the "&lt;".  Well, I just removed that bit and it<br>&gt; &gt; said:Feed Me!  and I put 42, and it said &gt;&gt;&gt; (I guess it's<br>&gt; &gt; satisfied now, with the whole feeding).  Well if I understood what<br>&gt; &gt; 'str' meant, then I could probably figure the rest out.  Well I<br>&gt; &gt; have to go do other things so I'll save the rest of this figuring<br>&gt; &gt; out till later.I shall return,Adam&gt; Date: Wed, 23 May 2007 12:12:16<br>&gt; &gt; -0400&gt; From: broek@cc.umanitoba.ca&gt; To: adamurbas@hotmail.com&gt; CC:<br>&gt; &gt; tutor@python.org&gt; Subject: Re: [Tutor] trouble with "if"&gt; &gt; adam<br>&gt; &gt; urbas said unto the world upon 05/23/2007 11:57 AM:&gt; &gt; &gt; &gt; Hi all,&gt;<br>&gt; &gt; &gt; &gt; &gt; I've been working with this new program that I wrote.  I<br>&gt; &gt; started out &gt; &gt; with it on a Ti-83, which is much easier to program<br>&gt; &gt; than python.  Now &gt; &gt; I'm trying to transfer the program to python<br>&gt; &gt; but its proving to be quite &gt; &gt; difficult.  I'm not sure what the<br>&gt; &gt; whole indentation thing is for.  And &gt; &gt; now I'm having trouble<br>&gt; &gt; with the if statement things. &gt; &gt; &gt; &gt; #"Circle Data Calculation<br>&gt; &gt; Program:"&gt; &gt; print "Welcome to the Circle Data Calcuation<br>&gt; &gt; Program."&gt; &gt; print&gt; &gt; &gt; &gt;     #"Menu 1:"&gt; &gt; print "Pick a shape:"&gt;<br>&gt; &gt; &gt; print "(NOTE: You must select the number of the shape and not the<br>&gt; &gt; shape &gt; &gt; itself)"&gt; &gt; print "1 Circle"&gt; &gt; print "2 Square"&gt; &gt; print<br>&gt; &gt; "3 Triangle"&gt; &gt; &gt; &gt;     #"User's Choice:"&gt; &gt; shape=raw_input("&gt; ")&gt;<br>&gt; &gt; &gt; &gt; &gt;         #"Select Given:"&gt; &gt; if shape == 1:&gt; &gt;         print<br>&gt; &gt; "Choose the given value:"&gt; &gt;         print "1 radius"&gt; &gt;<br>&gt; &gt; print "2 diameter"&gt; &gt;         print "3 circumference"&gt; &gt;<br>&gt; &gt; print "4 area"&gt; &gt; &gt; &gt; #"User's Choice:"&gt; &gt; given=raw_input("&gt; ")&gt; &gt;<br>&gt; &gt; &gt; &gt; if given == 1:&gt; &gt;         radius=raw_input("Enter Radius:")&gt; &gt;<br>&gt; &gt; diameter=(radius*2)&gt; &gt;         circumference=(diameter*3.14)&gt; &gt;<br>&gt; &gt; area=(radius**2*3.14)&gt; &gt;         print "Diameter:", diameter&gt; &gt;<br>&gt; &gt; print "Circumference:", circumference&gt; &gt;         print "Area:",<br>&gt; &gt; area&gt; &gt; &gt; &gt; if given == 2:&gt; &gt;         diameter=raw_input("Enter<br>&gt; &gt; Diameter:")&gt; &gt;         radius=(diameter/2)&gt; &gt;<br>&gt; &gt; circumference=(diameter*3.14)&gt; &gt;         area=(radius**2*3.14)&gt; &gt;<br>&gt; &gt; print "Radius:", radius&gt; &gt;         print "Circumference:",<br>&gt; &gt; circumference&gt; &gt;         print "Area:", area&gt; &gt; &gt; &gt; if given == 3:&gt;<br>&gt; &gt; &gt;         circumference=raw_input("Enter Circumference:")&gt; &gt;<br>&gt; &gt; radius=(circumference/3.14/2)&gt; &gt;         diameter=(radius*2)&gt; &gt;<br>&gt; &gt; area=(radius**2*3.14)&gt; &gt;         print "Radius:", radius&gt; &gt;<br>&gt; &gt; print "Diameter:", diameter&gt; &gt;         print "Area:", area&gt; &gt; &gt; &gt;<br>&gt; &gt; if given == 4:&gt; &gt;         area=raw_input("Enter Area:")&gt; &gt;<br>&gt; &gt; radius=(area/3.14)&gt; &gt;          &gt; &gt; This is the whole program so<br>&gt; &gt; far, because I haven't quite finished it &gt; &gt; yet.  But I tried to<br>&gt; &gt; get it to display another list of options after you &gt; &gt; select a<br>&gt; &gt; shape but it just does this.&gt; &gt; &gt; &gt; Pick a shape:&gt; &gt; 1 Circle&gt; &gt; 2<br>&gt; &gt; Square&gt; &gt; 3 Triangle&gt; &gt;  &gt;1&gt; &gt;  &gt;1&gt; &gt;  &gt;&gt;&gt;&gt; &gt; &gt; &gt; I'm not sure why<br>&gt; &gt; it does that but I do know that it is skipping the &gt; &gt; second list<br>&gt; &gt; of options.&gt; &gt; &gt; &gt; Another of my problems is that I can't figure<br>&gt; &gt; out how to get it to &gt; &gt; accept two different inputs for a<br>&gt; &gt; selection.  Like I want it to accept &gt; &gt; both the number 1 and<br>&gt; &gt; circle as circle then list the options for &gt; &gt; circle.  It won't<br>&gt; &gt; even accept words.  I can only get it to accept &gt; &gt; numbers.  It's<br>&gt; &gt; quite frustrating actually.&gt; &gt; &gt; &gt; Any advice would be greatly<br>&gt; &gt; appreciated.&gt; &gt; Thanks in advance,&gt; &gt; Adam&gt; &gt; &gt; &gt; &gt; &gt; &gt; Adam,&gt; &gt;<br>&gt; &gt; Could you send plain text email rather than html, please? At least<br>&gt; &gt; for &gt; me, your code's indentation is all messed up unless I take<br>&gt; &gt; some steps &gt; to rectify it.&gt; &gt; The problem is that raw_input<br>&gt; &gt; returns a string, and you are testing &gt; whether given is equal to<br>&gt; &gt; integers. See if this helps make things clear:&gt; &gt;  &gt;&gt;&gt; data =<br>&gt; &gt; raw_input('Feed me!')&gt; Feed me!42&gt;  &gt;&gt;&gt; type(data)&gt; &lt;type 'str'&gt;&gt;<br>&gt; &gt; &gt;&gt;&gt; data == 42&gt; False&gt;  &gt;&gt;&gt; int(data) == 42&gt; True&gt;  &gt;&gt;&gt;&gt; &gt; Best,&gt; &gt;<br>&gt; &gt; Brian vdB <br>&gt; <br>&gt; <br>&gt; Adam,<br>&gt; <br>&gt; As you can see from the above, the way hotmail is formatting things <br>&gt; makes the conversation a bit tricky :-) I'm only willing to spend so <br>&gt; much time trying to sort through it, so I hope what follows helps.<br>&gt; <br>&gt;  &gt;&gt;&gt; data = raw_input("Feed me!")<br>&gt; Feed me!42<br>&gt; <br>&gt; This calls the builtin function raw_input with a parameter setting the <br>&gt; prompt to "Feed me!" and assigns the result to data. Since I hit 42 <br>&gt; and then enter,<br>&gt; <br>&gt;  &gt;&gt;&gt; data<br>&gt; '42'<br>&gt; <br>&gt; Notice the quotes around 42. They indicate that the value of data is a <br>&gt; string. That's what this tells us:<br>&gt; <br>&gt;  &gt;&gt;&gt; type(data)<br>&gt; &lt;type 'str'&gt;<br>&gt; <br>&gt; The string '42' is not the same as the integer 42:<br>&gt; <br>&gt;  &gt;&gt;&gt; type(42)<br>&gt; &lt;type 'int'&gt;<br>&gt;  &gt;&gt;&gt; '42' == 42<br>&gt; False<br>&gt; <br>&gt; So, when you had an if test that was something like:<br>&gt; <br>&gt; if given == 1:<br>&gt;     # Do stuff here<br>&gt; <br>&gt; the equality comparison was never going to work---given was a string <br>&gt; returned by raw_input and no string is ever equal to an integer.<br>&gt; <br>&gt; What I suggested was taking the string returned by raw_input and <br>&gt; feeding it to int() to transform it from a string to an integer, and <br>&gt; allow your if test to stand a chance:<br>&gt; <br>&gt;  &gt;&gt;&gt; data = raw_input("Feed me!")<br>&gt; Feed me!42<br>&gt;  &gt;&gt;&gt; if data == 42:<br>&gt; ...   print "Matches!"<br>&gt; ...<br>&gt;  &gt;&gt;&gt; data = int(raw_input("Feed me!"))<br>&gt; Feed me!42<br>&gt;  &gt;&gt;&gt; if data == 42:<br>&gt; ...   print "Matches!"<br>&gt; ...<br>&gt; Matches!<br>&gt;  &gt;&gt;&gt;<br>&gt; <br>&gt; There are other ways, for instance:<br>&gt; <br>&gt;  &gt;&gt;&gt; data = raw_input("Feed me!")<br>&gt; Feed me!42<br>&gt;  &gt;&gt;&gt; if data == '42':<br>&gt; ...   print "Matches!"<br>&gt; ...<br>&gt; Matches!<br>&gt;  &gt;&gt;&gt;<br>&gt; <br>&gt; Here, instead of transforming data to an int and then testing for <br>&gt; equality with 42, I left data as a string and tested for equality with <br>&gt; the string '42'.<br>&gt; <br>&gt; The way calling int() is a bit better, I think. If the user enters a <br>&gt; few spaces, then 42 then a few more spaces, that way will still work:<br>&gt; <br>&gt;  &gt;&gt;&gt; data = int(raw_input("Feed me!"))<br>&gt; Feed me!    42<br>&gt;  &gt;&gt;&gt; if data == 42:<br>&gt; ...   print "Matches!"<br>&gt; ...<br>&gt; Matches!<br>&gt;  &gt;&gt;&gt;<br>&gt; <br>&gt; because<br>&gt; <br>&gt;  &gt;&gt;&gt; int('    42    ')<br>&gt; 42<br>&gt;  &gt;&gt;&gt;<br>&gt; <br>&gt; whereas<br>&gt; <br>&gt;  &gt;&gt;&gt; '    42    ' == '42'<br>&gt; False<br>&gt; <br>&gt; <br>&gt; I hope there is some help in there somewhere :-)<br>&gt; <br>&gt; Brian vdB<br><br /><hr />Create the ultimate e-mail address book. Import your contacts to Windows Live Hotmail. <a href='www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=RMT_TAGLM_HMWL_reten_impcont_0507' target='_new'>Try it!</a></body>
</html>