【问题标题】:Function to print blank lines Python [closed]打印空行Python的函数[关闭]
【发布时间】:2026-01-01 10:50:01
【问题描述】:

我需要创建一个名为nine_lines的函数,该函数将使用另一个名为three_lines的函数来打印九个空白行。

这就是我所拥有的,使用 3.4

  #creating a function within a function
  def new_line():
      print()
  def three_lines():
      new_line()
      new_line()
      new_line()
  def nine_lines():
      three_lines()
      three_lines()
      three_lines()
  nine_lines

它打印...

  >>>  ================================RESTART================================        
  >>> 
  >>>

【问题讨论】:

  • 你永远不会调用你的函数。缺少()
  • 投票结束为错字。

标签: python function parameters


【解决方案1】:
 #creating a function within a function
  def new_line():
      print()
  def three_lines():
      new_line()
      new_line()
      new_line()
  def nine_lines():
      three_lines()
      three_lines()
      three_lines()
  nine_lines()

我认为您在调用函数的九行之后缺少“()”。

另一种打印 9 行的方法是使用循环:

for i in range(9):
    print()

【讨论】: