+ 2
Add character to specific letter when using "for letter in word"
prefixes = 'JKLMNOPQ' suffix = 'ack' for letter in prefixes: if letter == 'Q': print(letter + 'u' + suffix) elif letter == 'O': print(letter + 'u' + suffix) else: print(letter + suffix) This works to print the correct names As all names are the letter in prefix followed by ack eg. Nack, Lack, Jack However, 2 names need a 'u'. Quack & Ouack Instead of doing an if and elif, Why cant I do if letter == 'Q' or 'O': When I try this, it adds 'u' to all prefixes... which is incorrect but logically it seems I should be able to do an OR statement
3 Answers
+ 3
prefixes='JKLMNOPQ'
suffix='ack'
for letter in prefixes:
if letter== 'O' or letter =='Q':
print (letter+'u'+suffix)
else:
print (letter+suffix)
+ 3
write
if letter == 'Q' or letter == 'O':
+ 1
Thanks Legends!