【问题标题】:Repeating function n times printx重复函数 n 次 printx
【发布时间】:2019-02-09 17:03:21
【问题描述】:

编写一个名为 printx() 的函数,它只打印字母“x”。然后编写一个名为 multiplex() 的函数,它接受一个整数作为参数,并通过多次调用函数 printx() 来打印整数所指示的字母“x”。

我已经想到了这个

def printx():
    print ("x")
printx()

但我不知道如何继续,感谢一些帮助;)

有什么建议吗?

【问题讨论】:

标签: python-3.x


【解决方案1】:

@Sjeng 这里是您要查找的代码。希望对您有所帮助。

def printx():
    print('x')

def muliplex(num): # num is the number of times you want x to be printed
    for i in range(num):
        printx()

【讨论】:

  • def printx(): print('x') printx() def muliplex(8): # num 是你希望在 range(8) 内打印 x 的次数:printx () 我这样做了,但仍然收到错误消息。
  • @Sjeng 它对我有用。您能否将错误消息发送给我,如果可能的话,还可以将您的代码截图发送给我吗?很乐意为您提供帮助。
猜你喜欢
  • 2020-01-18
  • 1970-01-01
  • 2021-11-30
  • 2011-11-13
  • 1970-01-01
  • 1970-01-01
  • 2021-10-19
  • 1970-01-01
  • 2012-12-04
相关资源
最近更新 更多