如何打印一个倒三角,正确分类?
***
**
*
这就是我试图让Python打印的方法。 条件如下: 1。必须使用嵌套循环或更多。
我已经用以下代码解决了此问题:
n = 0
for i in range(3,0,-1):
print(" "*n ,end = "")
n+=1
for j in range(0,i):
print("*", end="")
print()
但是,我试图查看是否可以在不声明“ n'varible 的情况下获得相同的输出 。 有办法这样做吗?
***
**
*
This is what I'm trying to get python to print.
The conditions are the following:
1. must use nested loops or more.
I've solved this with the following code:
n = 0
for i in range(3,0,-1):
print(" "*n ,end = "")
n+=1
for j in range(0,i):
print("*", end="")
print()
However, I'm trying to see if I can get the same output without declaring the 'n' variable.
Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以像这样利用str.rjust():
输出:
You could take advantage of str.rjust() like this:
Output:
我已经解决了以下内容:
I've solved this with the following: