why join() is not working here | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why join() is not working here

s=input("Enter string for reversed=") l=len(s) output='' l=l-1 while l>=0: output=output.join(s[l]) l=l-1 print(output)

20th Sep 2021, 2:40 PM
Abhishek Kumar
Abhishek Kumar - avatar
4 Answers
+ 4
This problem has been solved I recognise, but I just wished to mention that the function .reverse() exists, so the most concise code would be: s=input().reverse() print(s)
20th Sep 2021, 3:26 PM
Kamil Hamid
Kamil Hamid - avatar
+ 1
Just do: output += s[l] or if you want to optimize your whole code: s = input() s = s[::-1] print(s)
20th Sep 2021, 2:57 PM
Yahel
Yahel - avatar
0
Add a '+=' instead of '+' in the join line of code: while l>=0: output += output.join(s[l]) l=l-1 print(output)
20th Sep 2021, 3:07 PM
Karthikeyan R
0
join() returns a string, I think the problem this is. And you don't have to use join. s=input("Enter string for reversed=") l=len(s) output="" l = l - 1 while l>=0: output = output + s[l] l=l-1 print(output) It must also work. I hope, it helps. Happy coding!
20th Sep 2021, 3:07 PM
mesarthim
mesarthim - avatar