使用while循环完成:输入一个正整数,将其倒序输出。
想尝试用取出字符串最后一位数,然后抹掉原字符串末尾数字的方法建立循环。
>>> a = 12345
>>> b = str(a)
>>> while b:
print(b[-1],end='')
b=b[:-1]
54321
# 实际上不用循环就能实现:
>>> int(str(a)[::-1])
54321
看看这样可行?
num = list(input())
a = ''
while len(num)>0:
a += num.pop()
print(a)
res = ''
x = 1234
while x:
res += str(x % 10)
x //= 10