mode = input("请选择模式:")
n = int(input("请输入数字:"))
if mode == "A" or mode == "a":
# 模式A n:输入的层数 i:当前的层数
# 每行数字循环次数 == i
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end="\t")
print()
if mode == "B" or mode == "b":
# 模式B n:输入的层数 i:当前的层数
# 每行数字循环次数 == n - i + 1
for i in range(1, n + 1):
for j in range(1, n - i + 2):
print(j, end="\t")
print()
if mode == "C" or mode == "c":
# 模式C n:输入的层数 i:当前的层数
# 每行空格循环次数 == n - i
# 每行数字循环次数 == i
for i in range(1, n + 1):
for _ in range(n - i):
print(" ", end="\t")
for _ in range(i):
print(i,end="\t")
i -= 1
print()
if mode == "D" or mode == "d":
# 模式D n:输入的层数 i:当前的层数
# 每行空格循环次数 == i - 1
# 每行数字循环次数 == n - i + 1
for i in range(1, n + 1):
for _ in range(i - 1):
print("", end="\t")
for j in range(1, n - i + 2):
print(j, end="\t")
print()
题目 思路: #include <bits/stdc.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define lson p << 1
#define rson p << 1 | 1
const int maxn 1e6 5, inf 1e18, maxm 4e4 5;
c…