Python中打印空行的函数

3
我需要创建一个名为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================================        
  >>> 
  >>>

你从未调用你的函数。缺少 () - Mad Physicist
投票关闭为打字错误。 - Mad Physicist
1个回答

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()

我认为您在调用函数时漏掉了'()'括号,应该在nine_lines后加上括号。

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

for i in range(9):
    print()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接