forked from gjw199513/python100example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample23.py
More file actions
34 lines (33 loc) · 856 Bytes
/
Copy pathexample23.py
File metadata and controls
34 lines (33 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding:utf-8 -*-
__author__ = 'gjw'
__time__ = '2018/1/8 0008 上午 10:51'
# 题目:打印出如下图案(菱形):
"""
*
***
*****
*******
*****
***
*
"""
# 程序分析:先把图形分成两部分来看待,前四行一个规律,后三行一个规律,利用双重for循环,第一层控制行,第二层控制列。
import math
r = int(input("打印几(奇数)行的菱形"))
if r%2 == 0:
print("输入必须为奇数")
else:
c = math.ceil(r/2)
f = math.floor(r/2)
for i in range(c):
for j in range(c-1-i, 0, -1):
print(" ", end="")
for k in range(2*i+1):
print("*", end="")
print()
for i in range(f):
for j in range(0, i+1):
print(" ", end="")
for k in range(2*(f-i-1)+1):
print("*", end="")
print()