In your example your using arithmetic, but why not convert to a string to make life easier?
x = int(input("enter a number: "))
result = ""
for char in str(x)[::-1]:
result += char
print(result)
Note that [::-1]
means "iterate backwards" and that if your number ends with zeros, they'll appear at the start of the reversed string. If you want, you can trim them with lstrip
:
print(result.lstrip("0"))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…