Error in the code

prefixes = ‘JKLMNOPQ’
suffix = ‘ack’
for x in prefixes:
if x==‘O’ or x==“Q”:
suffix=“uack”
print(x+suffix)


the result of this code is

Jack
Kack
Lack
Mack
Nack
Ouack
Puack
Quack

Why am I getting Puack???

This is because you are not resetting your suffix variable.

If you think about your code through every step you’ll find that it sets your suffix to ‘ack’, then it goes through each prefix and prints out the prefix plus the suffix. If the prefix is ‘o’ or ‘q’, suffix is sent to ‘uack’, however it’s never set back to ‘ack’ if it’s not ‘o’ or ‘q’. So, once ‘o’ or ‘q’ presents itself once, the suffix will always be ‘uack’. I hope that helps!