发布网友 发布时间:2022-04-06 09:51
共4个回答
懂视网 时间:2022-04-06 14:12
python如何输出星号组成的菱形图形?python输出星号组成的菱形图形的方法:
读入一个整数N,N是奇数,输出由星号字符组成的菱形三角形,要求:????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
第1行1个星号,第2行3个星号,第3行5个星号,依次类推,最后n/2共n个星号,然后在依次递减到n行为一个星号。????????????????????????????????
def printStar(intNum): s = "*" spaceLength = intNum blockCount = int(intNum/2+1) for i in range(spaceLength): result = s.rjust(blockCount) if i >= int(spaceLength/2): print(result) s = s[2:] blockCount -= 1 else: print(result) s = s+(2*"*") blockCount += 1 def oddOReven(intNum): if intNum%2 == 0: print("please input a odd num data") else: printStar(intNum) if __name__ == '__main__': while True: try: intNum = eval(input("please input a odd num data ")) oddOReven(intNum) except BaseException as e: print("Please input as 1/2/3... Errorcode:%s" % e)
运行结果:
推荐教程:《python视频教程》
热心网友 时间:2022-04-06 11:20
Console.Write("请输入要打印的行数(奇数):");
int n = int.Parse(Console.ReadLine()) / 2 + 1; //这样就算出上部分的总行数了
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n - i; j++)
{
Console.Write(" ");
}
for (int k = 1; k <= 2 * i - 1; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
for (int i = 1; i < n; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(" ");
}
for (int k = 1; k <= (2 * n - 1) - 2 * i; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
热心网友 时间:2022-04-06 12:38
用什么编程语言?C的如下:热心网友 时间:2022-04-06 14:13
#include<stdio.h>