Reputation: 23
enter_inputs=int(input())
for i in range(enter_inputs):
rev=0
while i>0:
rev=(rev*10)+i%10
i=i//10
print(rev)
I am trying to get the reverse of a number in python but I am getting EOFError: EOF when reading a line why?
I guess my logic is correct.
Upvotes: 0
Views: 112
Reputation: 675
You are using using Python Man!, There would be inbuilt-functions for these basic uses.
number = int(input())
print(int(str(number)[::-1]))
Upvotes: 0
Reputation: 4472
To reverse a number can be done easily by using a list and then casting the result to int
enter_inputs=input() #input 12345
print(int("".join([i for i in enter_inputs if i.isnumeric()][::-1])))
Output
54321
This will take the input and split
each number init after that it will reverse the order join
the list and will cast it to int.
Upvotes: 1