+ 4

Please anyone help me with this code.

I want space between each number in output n=int(input()) list1=input() length=len(list1) if length == n : print(list1[::-1]) >>>Input (stdin) 5 12345 Your Output (stdout) 54321>>>

22nd Apr 2020, 2:33 PM
Ramya Thiurmalisamy
Ramya Thiurmalisamy - avatar
18 ответов
+ 4
print(*list[::-1]) Using this you will get your desired output.. just make this change(as mentioned above)in your code HOPE IT HELPS!!!☺️
22nd Apr 2020, 3:02 PM
ANJALI SAHU
+ 3
Ramya Thiurmalisamy * symbol is use to print the list elements in a single line with space and in strings as well
22nd Apr 2020, 5:07 PM
ANJALI SAHU
+ 2
Ok, then do one thing, create an empty string outside loop(for eg. x) and then do this - for i in list1[::-1]: x += i + " " print(x)
22nd Apr 2020, 4:53 PM
Varun Vaswani
Varun Vaswani - avatar
+ 2
you can use this code For i in list1[::-1]: X+=I+" " Print (x)
23rd Apr 2020, 1:02 AM
Sâñtôsh
Sâñtôsh - avatar
+ 2
n=int(input()) list1=input() length=len(list1) If length==n For i in list1: Print(i," ")
23rd Apr 2020, 10:08 PM
Yashpal Shinde
Yashpal Shinde - avatar
+ 1
Simply take every input as string eventhough it's a number... Or else use the logic of reverse of a number...(not exact logic, modify the code and use)
22nd Apr 2020, 2:53 PM
sarada lakshmi
sarada lakshmi - avatar
+ 1
What I am saying is - After the if statement, for i in list1[::-1]: print(i + " ")
22nd Apr 2020, 4:39 PM
Varun Vaswani
Varun Vaswani - avatar
+ 1
This is it. list=[12345] rev=list[::-1] print (rsd, sep=' ') To print in new lines, a loop is best.
24th Apr 2020, 3:31 AM
Carlson Samba
Carlson Samba - avatar
0
Add a for loop in it printing each element + " "(space)..
22nd Apr 2020, 2:38 PM
Varun Vaswani
Varun Vaswani - avatar
0
RAJESH SAHU yeah!!! It's work.but can you explain how it is?
22nd Apr 2020, 4:22 PM
Ramya Thiurmalisamy
Ramya Thiurmalisamy - avatar
0
Varun Vaswani can you explain how I can use for loop here?I can't able to understand what you say!!
22nd Apr 2020, 4:24 PM
Ramya Thiurmalisamy
Ramya Thiurmalisamy - avatar
0
Varun Vaswani but it givese a output in newlines not in a same line.😑😑🤔
22nd Apr 2020, 4:42 PM
Ramya Thiurmalisamy
Ramya Thiurmalisamy - avatar
0
@ Varun Vaswani ok I will check it out.Tq
22nd Apr 2020, 4:55 PM
Ramya Thiurmalisamy
Ramya Thiurmalisamy - avatar
0
Welcome
22nd Apr 2020, 5:00 PM
Varun Vaswani
Varun Vaswani - avatar
0
@yeah!!!it's working 👍👍🤝🤝🙏🤩🙏✨💫
22nd Apr 2020, 5:01 PM
Ramya Thiurmalisamy
Ramya Thiurmalisamy - avatar
0
Varun Vaswani it'll also print space at the end which we won't need...!!
23rd Apr 2020, 5:29 AM
sarada lakshmi
sarada lakshmi - avatar