Python经典练习题:使用Python打印菱形


def star():
    line_number = int(input('请输入打印小星星行数'))
    if line_number % 2 == 0 or line_number <= 3:
        print('请输入一个奇数,且大于三')
        return star()
    fre = int((line_number - 1) / 2)
    for number in range(1, 2 * fre, 2):
        print('*' * number)
    print('*' * (2 * (fre + 1) - 1))
    i = 2
    for number in range(2 * fre - 1, 0, -2):
        print(' ' * i, '*' * number, sep='')
        i += 2
if __name__ == '__main__':
    star()

你可能感兴趣的:(笔记)