关于python有限制性的编码问题?

1,需要用户输入一个整数
2,从0开始,已每次+1的规则依次输出整数,
并在数字前加入等同于数字的空格量
然后从当前数字再返回0
如输入0则直接结束程序,不需要任何输出
3,例:
输入整数:5
0
1
2
3
4
3
2
1
0

4,限制:只能使用一个while,不能使用for,if,abs,list,len等指令

# -*- coding: UTF-8 -*-
import math
n = 5 # int n = int(input())
m = -n + 1
i = 2 * n
while i > 1:
    o = n - int(math.sqrt(m * m)) - 1
    i = i - 1
    m = m + 1
    s = ' '
    s = s * o
    print(s + str(o))
输出
0
 1
  2
   3
    4
   3
  2
 1
0

问题解决的话,请点下采纳。

ins=input("请输入一个整数:")
n= int(ins)

def output(i, n, forward):
    while i>=0 and i<n:
        print(' '*i +str(i))
        i = i + forward


output(0, n, 1)
output(n-2, n, -1)