[英]Calling a function within a function [Python]
The instructions that I've been given tells me create 2 functions: first one (helloWorld) just has to print a basic string but the second one (helloWorldNTimes) has to call the first one 'n' amount of times. 我得到的指令告诉我创建2个函数:第一个函数(helloWorld)仅需要打印一个基本字符串,而第二个函数(helloWorldNTimes)必须调用第一个'n'次。 This is what I have so far - I either don't understand the question completely or misinterpreting it.
到目前为止,这就是我的意思-我要么不完全理解这个问题,要么误解了它。
def helloWorld():
print('Hello World')
def helloWorldNTimes(n):
def main():
helloWorldNTimes(7)
main()
You have to study loops in programming language. 您必须学习编程语言中的循环。 Especially for loop.
特别是对于循环。
You have to call function inside a loop. 您必须在循环内调用函数。 It can be either while or for loop.
它可以是while或for循环。 Then only it can be called n number of times.
那么只有它可以被调用n次。
Example : 范例:
def helloWorld():
print ("Hello, World!")
for x in range(7):
helloWorld()
your 2nd function doesn't do anything... you have to call a loop "n" times to have it done: 您的第二个函数什么也没做...您必须调用循环“ n”次才能完成:
def helloWorld():
print('Hello World')
def helloWorldNTimes(n):
for x in range(7):
helloWorld()
def main():
helloWorldNTimes(7)
main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.