在python中以设置的宽度打印ASCII菱形 [英] Printing an ASCII diamond with set width in python
本文介绍了在python中以设置的宽度打印ASCII菱形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是的,这是一项家庭作业.但是请,如果您要给我代码,请告诉我您已完成的详细操作.我对此很陌生.
Yes, this is a homework task. But just please, if you're going to give me the code please tell me what you've done in detail. I am extremely new to this.
因此,任务是根据用户输入的宽度来打印ASCII菱形.我可以做钻石的上半部分,而不能做钻石的下半部分,由于某种原因,我只是看不到该怎么做.
So the task is to print an ASCII diamond depending on what width the user inputs. I can do the first half of the diamond, just not the bottom half, for some reason I just cannot see how to do it.
这是我的代码:
wid = int(input("Width: "))
i = 1
while i <= wid:
print(" " * (wid - i) + "* " * i)
i = i + 1
如果wid = 5,将输出以下内容:
Which will output the following if wid = 5:
Width: 5
*
* *
* * *
* * * *
* * * * *
推荐答案
i=1
j=input("ENTER NO =")
l=0
for i in range(i,j-((j/2)-1),1):
print (' ' * ((j+1)/2-i)+'*' *(i*2-1))
l=(j/2+1)
while (i==l):
i=1
for i in range(i,j,1):
print (' ' *((i*2)-i)+'*' *(j-i*2))
if [i==j-1]:
l=raw_input('<press enter to exit>')
这篇关于在python中以设置的宽度打印ASCII菱形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文