我不需要帮助,这是非常容易的,我需要帮助来决定我应该使用哪几种方式。你觉得我能用递归吗?我至少需要一个
if
但是,上面写着
仅
函数调用
当然,我正在考虑使用递归,但是我需要一个if-否则,但是它说“只有函数调用”。
考虑下面的Python函数,它输出4次来自著名计算机科学家的引用:
def print4x() :
print("Controlling complexity is the essence of programming!")
print("Controlling complexity is the essence of programming!")
print("Controlling complexity is the essence of programming!")
print("Controlling complexity is the essence of programming!")在一个完整的Python程序中使用此print4x函数,该程序输出Kernighan引用64次。您的解决方案必须包含一个主函数、print4x函数和至少一个附加函数。你不应该用任何循环或者同时循环之类的-
只是函数调用!
简单地调用print4x 16次并不是一个可接受的解决方案。
发布于 2022-07-01 03:27:42
由于我们不能使用循环或条件语句,而且只能使用函数,所以这里是我的解决方案。
def print4x() :
print("Controlling complexity is the essence of programming!")
print("Controlling complexity is the essence of programming!")
print("Controlling complexity is the essence of programming!")
print("Controlling complexity is the essence of programming!")
def repeat(num):
print4x()
numbers = (1, 2)
result = list(map(repeat, numbers))在这里,我们只是在使用函数。是的,可以有一个改进的代码,我是开放的意见,在意见。
关于问题语言的探讨
如果我们严格地坚持问题的语言,它说只是函数调用
这使我们无法使用循环和条件语句,这使得使用递归变得困难。
但是,一些内置函数也可以作为循环工作(如map())。因此,这个问题需要详细说明哪些函数是允许的。
https://stackoverflow.com/questions/72824054
复制相似问题