As the title says, the output contains some uppercase letters, but for the life of me I can't figure out why. <=== Read the entire post to understand the problem. This is the code snippet which I'm assuming causes the 'error'.
def translate(s):
i = 0
word = ""
for letter in s:
word += letter.upper() + (letter * i) + "-"
i += 1
The function takes a string as input and returns a string with first letter being capital and the following letters being multiplied by 1 += 1 (+1 for each set of different letters), followed by "-". Example:
Input and Output
Input: "ZpglnRxqenU"
Expected Output: "Z-Pp-Ggg-Llll-Nnnnn-Rrrrrr-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-Uuuuuuuuuuu"
Actual Output: "Z-Pp-Ggg-Llll-Nnnnn-RRRRRR-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-UUUUUUUUUUU"
The problem
As you can see, the R:s are all uppercase and so is the U:s. My question is: Why are they uppercase? I know why the first letter is, and that's intended but there should never be more than one uppercase (the first letter) per section (a section being within the bounderies of "-" and "-").
For further refrence: https://www.codewars.com/kata/5667e8f4e3f572a8f2000039/
OBS: I'm not doing this to get an answer to the codewars challenge.
This is the entire code.
def translate(s):
i = 0
word = ""
for letter in s:
word += letter.upper() + (letter * i) + "-"
i += 1
eq1 = list(word)
eq1.reverse()
eq1.remove("-")
eq1.reverse()
word = ""
for y in eq1:
word += y
return word
Lines 7-12 are just my way of dealing with removing the last "-". The output would have an "-" at the end if it wasn't there. I know it's a bad way of dealing with it but I just wanted to finish it as fast as possible.