+ 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

25th Sep 2017, 10:23 AM
JUGHEAD
JUGHEAD - avatar
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)
25th Sep 2017, 11:04 AM
Doniyorbek
Doniyorbek - avatar
+ 3
write if letter == 'Q' or letter == 'O':
25th Sep 2017, 11:22 AM
Doniyorbek
Doniyorbek - avatar
+ 1
Thanks Legends!
25th Sep 2017, 1:28 PM
JUGHEAD
JUGHEAD - avatar