I don't understand why my code doesn't work.
The code is:
def trans(old):
length = len(old)
new = []
new = old
for i in range(0,length):
print(old[length-i-1])
for i in range(0,length):
new[i] = old[length-i-1]
print("new:",new[i]," [i]:",i," old:",old[length-i-1]," length-
i-1:",length-i-1)
ihavenoideawhatimdoing = " ".join(new)
return new
Instruction:
1. def trans(old): Input sentence in (old)
2. length(len): Take number of elements in the sentence
3. new = []
and new = old
is to make a container with the same size for the new word
4. First for
loop = I wanted to see the words in the original sentence backwards
5. My problem is in the second for
loop. See the output
6. What comes next is related to the problem I'm solving but not to the problem I'm having
Input sentence: "please help me solve this"
I didn't any label for the next batch of words but it's supposed to be:
old(length-0-1) -> old(5-0-1) -> old(4): this
old(3): solve
old(2): me
old(1):help
old(0): please
Now, what's iffy is in the next for
statement at length-i-1 = 1 where instead of being "help", it's "solve."
Both codes are familiar so I'm stuck at what else could be wrong.