python图案右三角带有python的循环
我需要以特定的形状和顺序打印数字,不允许 ,但是我不明白,我也无法在网上找到任何可以帮助我了解如何了解的我可以将图形移到右边,还是如何将其翻转。这是我目前拥有的代码。我想使用一个三角洲(8个空间)乘以数字的数字来向右移动形状,并将顶部形状后面的所有东西转换为空的空间,但不知道该怎么做
i = 1
delta = 8
while i <= 5:
j = 1
while j <= i:
print(j, end="")
j += 1
print()
i += 1
a = 5
while a >= 1:
b = 1
while b <= a:
print(b, end="")
b += 1
print()
a -= 1
这是我得到的结果,我需要将第一个循环移至右边
之后,我需要将较低的循环倒置,并在使它看起来与较低的循环一样,我能够使用一个循环进行操作,但是我不确定如何使用for lim lian ther循环进行操作并保持形状。
I need to print the numbers in a specific shape and order with a while loop, for loop is not allowed, but I don't understand nor can I find anything on the web that can help me understand how can I move the figure a bit to the right or how I can flip it around. Here is the code I have at the moment. I wanted to use a delta, which is 8 spaces multiplied with the digits behind to move the shape to the right and convert everything behind the top shape into empty spaces but don't know how to do it
i = 1
delta = 8
while i <= 5:
j = 1
while j <= i:
print(j, end="")
j += 1
print()
i += 1
a = 5
while a >= 1:
b = 1
while b <= a:
print(b, end="")
b += 1
print()
a -= 1
and here is the result I get,I need to move the first loop to the right so I can get this shape
After that I need to make the lower loop inverted and to use the number 1 from the top loop to make it seem like it fits with the lower loop one, I was able to do it with a for loop but i am not sure how I can do it with a while loop and maintain the shape.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对可以使用三角洲,只需在每个数字打印循环之前打印它即可获得间距。对于第二个循环,您可以每次将其减少2个,以便结束与第一个循环启动相同的位置。
编辑:这看起来像是一堂课的问题,所以我试图将代码保留在您的样式中
You can definitely use a delta, just print it before each number print loop to get the spacing. For the second loop you can decrement it by 2 each time so the ending stays in the same place as the first loop starts.
Edit: This is looking suspiciously like a question from a class so I tried to keep the code in what appears to be your style lol