Flip the String Practice | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

4th Jul 2021, 11:53 PM
estrin42
estrin42 - avatar
5 Answers
+ 4
estrin42 yes, overcomplicating: words = input() print(words[::-1])
5th Jul 2021, 12:07 AM
visph
visph - avatar
+ 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
5th Jul 2021, 6:08 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
OMG!!! just do like that: word = input() or "boom" print(word[::-1]) #yes, that's it. ))))
5th Jul 2021, 6:13 AM
Shadoff
Shadoff - avatar
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
5th Jul 2021, 12:08 AM
Simon Sauter
Simon Sauter - avatar
0
hello friends try this one it works well u="" words=list(input()) rword=(words[::-1]) for i in rword: u+=i print(u)
2nd Oct 2021, 6:54 AM
Mahdi Bitaab
Mahdi Bitaab - avatar