如何在python中打印以下数字模式?

时间:2019-02-07 10:43:17

标签: python python-3.x numbers

我要打印以下图案:

1
2 2
3 3
4 4
3 3
2 2
1  # i want this 

我正在python 3中打印此模式,但无法打印完全相同的模式

for row in range(1, 5): 
    for column in range(2): 
        print(row, end=" ") 
        print("\n") 
for row in range(1, 5): 
    for column in range(1, row + 1): 
        print(column, end=' ') 
        print("") # this is my code
 1 1 

 2 2 

 3 3 

 4 4 

 1 
 1 2 
 1 2 3 
 1 2 3 4  # this my output

1 个答案:

答案 0 :(得分:0)

尝试一下。此代码缩进不正确。自己输入,然后查看输出。

const std::vector foo({1, 2, 3, 4});
foo.clear();

输出:

num = int(input("Enter the number"))
for i in range(1,num+1):
   if i == 1:
       print(i)
   else:
       print(i, i, sep=" ")
for i in range(num-1, 0, -1):
   if i == 1:
       print(i)
   else:
       print(i, i, sep=" ")