Here is my code:
t = int(input())
for _ in range(t):
n = input()
print(n[::-1])
Here is my code:
t = int(input())
for _ in range(t):
n = input()
print(n[::-1])
Which Problem are you trying to solve?
Edit:
If it’s this: FLOW007 Problem - CodeChef, then your solution gives the wrong output for the sample test input: the Online Judge compares your output with the expected output as strings, so your output must match the expected output exactly.
You can use lstrip() function to remove 0 from starting. Your code will print the reverse string because you are using string. You can also type cast into int so that automatically 0 from starting will be removed.
Personally I will not recommend to reverse number using this way.
t = int(input())
for _ in range(t):
n = input()
print(n[::-1].lstrip("0"))
Just a small suggestion, while posting your doubts, please specify which question you are asking for, otherwise its very difficult to answer.
But from the structure of your code, I guess you are asking for Reverse the Number problem.
For that you can refer to my solution below:
t = int(input())
for tc in range(t):
n = input()
ans = ''
for item in n:
ans = item+ans
print(int(ans))
Note: If you do ans = ans+item in code, instead of ans = item+ans, then you would end up getting the same number that you have taken input.
Don’t forget to convert the string into integer format at last. Your solution is all good, but its giving WA just because of this small thing.