<div><div>Hello! I'm also new, to both Python and this list, but I think I know this one, so it's a good chance for me to post.<br><br>The second block of code doesn't work either--it always sets stock = 2. I believe that the problem is that the code you've really written is:
<br><br>if (texture == "flaky") or "caked":<br>...<br><br>If either expression evaluates to True, the first block will be called. Problem is, bool("caked") evaluates to True, as bool(s) is False if s == "" and True otherwise, when s is a string. The reason for this is it allows for really brief code like, I dunno:
<br><br>a = "Hello."<br>while a:<br> a = a[:-1]<br><br>This removes a character from the end of a until a is empty.<br><br>This code would work:<br><br>if texture == "flaky" or texture == "caked":
<br> stock = 1<br>else:<br> stock = 2<br> <br><br>The problem with learning Python from a Pascal book is that you're going to miss all of the syntactical shortcuts that makes Python powerful. For instance, you could use the line 'if texture in ["flaky","caked"]'. There's definitely a good one-liner for this, (the veterans should chime in here) but the best I could come up with was this one: (it's a hack)
<br><br>stock = 2 - (texture in ["flaky","caked"])<br><br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>
<font face="Arial" size="2"><font color="#ff0000" face="Arial" size="2">if texture ==
"flaky" or "caked":<br> stock = 1</font></font></div>
<div>
<div><font color="#ff0000"><font face="Arial" size="2">else:<br>
stock = 2</font> </font></div>
<div> </div>
<div>This never worked. Cigars with "varied, fluffy, granular, " textures
always ended up as stock 1. So did the "flaky and caked". </div>
<div>-----------------------------------------------------------------------------</div></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">When I changed the line to:</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font color="#ff0000" face="Arial" size="2">if texture != "flaky" or
"caked":<br> stock = 2<br>else:<br> stock =
1</font></div>
<div><font face="Arial" size="2">the program works great.</font> <font face="Arial" size="2"> I have no idea why. Can anyone help
me.</font></div>
<div> </div></blockquote></div>