Python编程输出数字三角形(python输出由数字组成的三角形)
Python 打印各种三角形
rows = int(input('输入列数:'))
for i in range(1, rows):
print('*' * i)
for i in range(1, rows):
for j in range(i):
print("*", end="")
print("")
rows = int(input('输入列数:'))
for i in range(1, rows):
print(' * ' * i)
for i in range(1, rows):
for j in range(1, i + 1):
print(" * ", end="")
print("")
rows = int(input('输入列数:'))
for i in range(1, rows):
if i % 2 != 0:
str = ('*' * i)
print(str.center(9, ' '))
rows = int(input('输入列数:'))
for i in range(0, rows):
print(" * " * rows)
for i in range(0, rows):
for j in range(0, rows):
print(" * ", end="")
print(" ")
for x in range(10):
for i in range(x, 10):
print('*', end='')
print('')
print('同一行打印直角三角形')
for j in range(10):
for x in range(0, j):
print(' ', end='')
for n in range(j, 19 - j):
print(' ', end='')
for k in range(0, j):
print(' ', end='')
print('')
print('直角三角形拼装心形')
for j in range(8):
for x in range(0, j):
print(' ', end='')
for n in range(j, 19 - j):
print(' ', end='')
for k in range(0, j):
print(' ', end='')
print('')
for i in range(10):
for j in range(0, 0 + i):
print(end=' ')
for k in range(0 + i, 10):
print('*', end=' ')
print('')
print('打印倒立等腰三角形1')
for j in range(10):
for x in range(0, j):
print(end=' ')
for n in range(j, 15 - j):
print('*', end='')
print('打印倒立等腰三角形2')
for i in range(10):
for j in range(0, 0 + i):
print(end=' ')
for k in range(0 + i, 10):
print('*', end=' ')
print('')
print('同一行打印两个等腰三角形')
for i in range(10):
for j in range(0, 10 - i):
print(end=' ')
for k in range(10 - i, 10):
print(' ', end=' ')
for n in range(0, 0):
print(end=' ')
for m in range(0 + i, 10):
print(' ', end=' ')
for jj in range(10, 10):
print(end=' ')
for kk in range(10 - i, 10):
print(' ', end=' ')
print('')
print('等腰三角形拼装心形')
for i in range(10):
for j in range(0, 10 - i):
print(end=' ')
for k in range(10 - i, 10):
print(' ', end=' ')
for n in range(0, 0):
print(end=' ')
for m in range(0 + i, 10):
print(' ', end=' ')
for jj in range(10, 10):
print(end=' ')
for kk in range(10 - i, 10):
print(' ', end=' ')
print('')
for i in range(20):
for j in range(0, 0 + i):
print(end=' ')
for k in range(0 + i, 20):
print('*', end=' ')
print('')
print('打印正方形')
for i in range(10):
for j in range(0, 10 - i):
print(end=' ')
for n in range(0, 0 + i):
print(end=' ')
for m in range(0 + i, 10):
print(' ', end=' ')
for k in range(10 - i, 10):
print(' ', end=' ')
print('')
python 3.6.3,怎么写出一个数字组成的三角形
import stringnums = string.digitsdef check(a): if type(a) is not str: return False else: for i in a: if i not in nums: return False return True使用字符串模块里面的宏定义digits,它定义了0到9等10个数字。循环判断你给定的字符串里面的每个字符,如果发现其中一个字符不是数字就返回错误,如果遍历完了都没有发现不是数字的就返回正确
用Python编写,print("X"),列出1个三角形,第1行1个X居中,第2行2个X居中,第3行5个X居中,列出10行来。
1、创建python文件,testtriangle.py;
2、编写python代码,打印三角形;
for?i?in?range(1,?11):
print('?'.join('X'?for?j?in?range(i)).center(19,?'?'))
3、窗口右击,选择‘在终端中运行Python文件’;
4、在输出窗口中,可以发现三角形已输出;
python本题要求编写程序,倒序输出n行由指定数字开始构成的左下三角形数字阵列?
以下是一个简单的Python程序,用于倒序输出n行由指定数字开始构成的左下三角形数字阵列:
n = int(input("请输入行数:")) # 输入行数
start_num = int(input("请输入起始数字:")) # 输入起始数字
# 构造数字阵列
matrix = []
for i in range(n):
row = [start_num + j for j in range(n-i)]
matrix.append(row)
start_num += 1
# 倒序输出数字阵列
for i in range(n):
row = matrix[n-1-i]
for j in range(n-i):
print(row[j], end=" ")
print()
运行程序后,会提示用户输入行数和起始数字。程序会根据用户输入的行数和起始数字构造一个左下三角形数字阵列,并倒序输出该数字阵列。例如,如果输入行数为5,起始数字为1,则输出结果为:
5 6 7 8 9
4 5 6 7
3 4 5
2 3
1
该程序使用了列表推导式和嵌套循环来构造数字阵列,并使用循环来倒序输出数字阵列。