发布网友 发布时间:2022-04-06 09:51
共2个回答
懂视网 时间: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
#include "stdio.h"