我有一个计数器函数counter(),它应该首先计数到2并返回一个函数 h()然后继续计数到3并返回函数g()并中断。
def h():
return "hi"
def g():
return "hallo"
def counter():
i = 0
# If i is equal or less than 2, return the function h() and continue
while i <= 2:
i = i +1
return h(),i
continue
# If i equals 3, return function g() and break/end counting
# The current issue with this code is that the function g()
# isn't returned and the condition itself doesn't seem to
# respond, or count up to 3 from 2.
if i == 3:
return g()
return i
print counter()