I’m new to python, I’m using v2.7
#Filename:ReverseNumber.py
data=int(raw_input("Enter any number: "))
print "Reverse of the number: ",
while data!=0:
a=data%10
print a,
data=data/10
So the output should come like :
Enter any number: 123
Reverse of the number: 321
but instead of this in the second line it is printing one extra space before every number.
How to overcome this?
You could modify your approach in a number of ways:
Create a list of your values, then join them with a blank string for printing:
You could skip the whole integer conversion step and just reverse the incoming string:
You could skip the integer step and join the result of reversed:
You could add a
backspaceto your print commands for your numbers:Hopefully one of those fits your requirements.