坚持打印金字塔代码,虽然我的代码是正确的,但我的 jupyter notebook 没有打印出准确的答案

stuck to printing pyramid code although my code is correct but my jupyter notebook doesn't print me the exact answer

Screenshot of code and output

代码

num = int(input("Enter the number of rows:"))
for i in range(0,num):
  for j in range(0,num-i-1):
    print(end="")
  for j in range(0,i+1):
    print("*",end="")
  print()

当前输出

*
**
***
****
*****
******
    

答案与金字塔不完全相同,请看图

我认为您希望金字塔居中而不是向左侧倾斜。为此,您必须相应地调整循环中星星前后的间距:

更改代码

num = int(input("Enter the number of rows:"))
for i in range(0,num):
  for j in range(0,num-i-1):
    print(end=" ")
  for j in range(0,i+1):
    print("*",end=" ")
  print()

输出

     * 
    * * 
   * * * 
  * * * * 
 * * * * * 
* * * * * *