xqzz.net
当前位置:首页 >> 用Python怎样输出完整的菱形? >>

用Python怎样输出完整的菱形?

line=int(input('请输入菱形行数:')) for i in range(1,line+1): for j in range(1,line+1-i): print(' ',end='') for k in range(1,2*i): print('*',end='') print() for i in range(1,line): for j in range(1,i+1): print(' ',end='') for k in range(1,2*line-2*i): print('*',end='') print()

循环输出,第一行输入n个空格+*+n个空格 第二行输入n-1个空格+*+n-1个空格以此类推就好

#include int main() { int i, j, n; printf("请输入n: "); scanf("%d", &n); /* * 以下注释假设n=3进行分析 */ // 菱形上半部 for (i=0; i for (j=0; j printf(" "); } for (j=0; j

如果存在序列占用多行的情况:import itertools def file2dict(filename): name = "" content = "" dct = {} for ln in itertools.ifilter(None, itertools.imap( lambda s: s.strip(), open(filename, 'rt') )): if ln.startswith(">"): if content: dct[name] = content

python: >>> for i in range(0,6): print abs((5/2 + 1 - i))*" " + (5-2*abs((5/2 + 1 - i)))*"*" + abs((5/2 + 1 - i))*" "

//能打印出菱形就能打印出其他图形了,下面是打印菱形的代码.#include#definen3intmain(){inti,j;for(i=0;i=0;i--){for(j=1;j

python:>>> for i in range(0,6): print abs((5/2 + 1 - i))*" " + (5-2*abs((5/2 + 1 - i)))*"*" + abs((5/2 + 1 - i))*" "

给:#include<conio.h>#include<stdio.h> int main( void ) { int i,j,n,k; puts("input a number:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(k=1;k<=n-i;k++) printf(" "); for (j=1;j<=i;j++) printf("* "); printf("\n"); } for(i=1;i<=n;i++) { for(j=1;j<=i;j++)

屡考屡败的宋秀才不幸早夭,上天怜其文才出众,差他当了梓潼府的司文郎.宋途经报国寺,偶遇考生王平子、余杭生.两人请盲僧评试文章,盲僧大赞王生才华横溢,而余生庸庸无为.不料考试结果是余生名列榜首,而王生名落孙山.宋秀才怕王平子想不开,发生平相慰:是天?是命?该哭?该笑?不得知乎!相安为宜.

网站首页 | 网站地图
All rights reserved Powered by www.xqzz.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com