Jul-18-2018, 02:32 PM
Hello,
I was given a homework, the output should look like this:
W
Wo
Wor
Worl
World
World
World H
World He
World Hel
World Hell
World Hello
The teacher suggested this solution:
I dont understand why we need an additional tmp variable. Could someone please explain it to me, or have a better, more pythonic solution?
I was given a homework, the output should look like this:
W
Wo
Wor
Worl
World
World
World H
World He
World Hel
World Hell
World Hello
The teacher suggested this solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
userInput = 'Hello World' userInput = userInput.split( ' ' ) userInput = userInput[:: - 1 ] userInput = ' ' .join(userInput) tmp = '' for char in userInput: tmp + = char print (tmp) |