I think the "fail" occurs because it will occur every time the char_loc is not between 51 and 55.
if (char_loc >= 11 and char_loc <= 15):
if (char_loc >= 21 and char_loc <= 25):
if (char_loc >= 31 and char_loc <= 35):
if (char_loc >= 41 and char_loc <= 45):
if (char_loc >= 51 and char_loc <= 55):
else:
What I think you'd want to do here is use elif, which will only fire if the previous checks don't trigger.
if (char_loc >= 11 and char_loc <= 15):
elif (char_loc >= 21 and char_loc <= 25):
elif (char_loc >= 31 and char_loc <= 35):
elif (char_loc >= 41 and char_loc <= 45):
elif (char_loc >= 51 and char_loc <= 55):
else:
In regards to the multiple @ symbols, I think this may play a part. Currently you have:
if char_loc == k:
x0.insert(i, '@')
else:
i += 1
k += 1
What I think you're looking to do is:
if char_loc == k:
x0.insert(i, '@')
i += 1
k += 1
Since you want k to change every time that loop iterates.
One last thing that I would suggest is since you have:
i =0; k = 21
i =0; k = 31
i =0; k = 41
i =0; k = 51
You will probably want to add
i =0; k = 11
To the first one.
Hope that helps.