Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

*Y*

macrumors regular
Original poster
Oct 19, 2004
184
0
VA
Hey guys,

I am pretty new on the programming scene. I have a question for you Python gurus. Why wont this:

prefixes = "JKLMNOPQ"
suffix = "ack"
for letter in prefixes:
if letter=="O"or"Q":
print letter + "u"+suffix
else:
print letter + suffix

give me this:

Jack
Kack
Lack
Mack
Nack
Ouack
Pack
Quack

Thanks.:D
 

therevolution

macrumors 6502
May 12, 2003
468
0
You can't combine the test for 'O' and 'Q' that way. You need to do it like this:

Code:
prefixes = "JKLMNOPQ"
suffix = "ack"
for letter in prefixes:
  if letter == "O" or letter == "Q":
    print letter + "u"+suffix
  else:
    print letter + suffix

Remember, when you are evaluating an expression, both sides of your "or" need to evaluate to a "true" or "false". "Q" isn't a logical value to put there.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.