prefixes = 'JKLMNOPQ'
suffix = 'ack'
I am meant to add the prefixes and suffixes and Output should be Jack, Kack, Lack, Mack, Nack, Ouack, Pack, Quack. I already got how to add the suffixes to the prefixes but the extra "u" for O and Q throws me off completely.
this is how I did it:
for letter in prefixes:
print(letter suffix)
CodePudding user response:
you don't make it clear in the question if there are any other conditions but it seems that you simply want to add this extra "u" if the first letter is "o" or "q", you can make a list to store these letters and use an if
statement to check
prefixes = 'JKLMNOPQ'
suffix = 'ack'
add_u_letters = ['O', 'Q']
for letter in prefixes:
if letter in add_u_letters:
print(letter 'u' suffix)
else:
print(letter suffix)
CodePudding user response:
This should work:
prefixes = 'JKLMNOPQ'
suffix = 'ack'
for letter in prefixes:
if letter in 'OQ':
print(letter 'u' suffix)
else:
print(letter suffix)
CodePudding user response:
I think a simple if would do that:
for letter in prefixes:
if suffix in ['O','Q']:
print(letter 'u' suffix)
else:
print(letter suffix)