Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
34 lines (33 loc) · 856 Bytes

File metadata and controls

34 lines (33 loc) · 856 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.