0
Flip the String Practice
The practice problem request a string input to be reversed and reprinted as output. The examples show the string output on a single line, and while my code checks out according to the app: #your code goes here words = list(input()) sdrow = words[::-1] for i in sdrow: print (i) It prints the output one letter to a line and looks horrible. What can be done to make the output a single line string? Am I just overcomplicating the problem for no reason?
5 Answers
+ 4
estrin42
yes, overcomplicating:
words = input()
print(words[::-1])
+ 1
Here are some methods to reverse a string:
words = input()
#1
print(words[::-1])
#2
print("".join(words[i] for i in range(len(words)-1, -1, -1)))
#3
for i in range(len(words)-1, -1, -1):
print(words[i], end="")
#4
print(*reversed(list(words)), sep="")
#5
def rev(a):
String = ""
for x in a:
String = x + String
return String
print(rev(words))
# Hope this helps
+ 1
OMG!!!
just do like that:
word = input() or "boom"
print(word[::-1])
#yes, that's it. ))))
0
You can convert the list back to a string and then print the string. Here are some ways of doing that:
https://pytutorial.com/JUMP_LINK__&&__python__&&__JUMP_LINK-convert-list-to-string
0
hello friends try this one it works well
u=""
words=list(input())
rword=(words[::-1])
for i in rword:
u+=i
print(u)