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)
4 odpowiedzi
+ 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)
+ 1
Just do:
output += s[l]
or if you want to optimize your whole code:
s = input()
s = s[::-1]
print(s)
0
Add a '+=' instead of '+' in the join line of code:
while l>=0:
output += output.join(s[l])
l=l-1
print(output)
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!