[英]How to return the value of a while loop counter
我想在每次循环重复后返回 while 循环的计数器 i 和 b 以用于另一个 function。我没有发现任何与返回这些值相关的内容。
def dis(reps, towards, back):
t = 0 # move towards t times
b = 0 # move back b times
i = 0 # repetitions
n = 1 # counts every step
while i < reps:
while t < towards:
do_something()
i += 1
n +=1
while b < back:
do_something()
n += 1
b += 1
t = 0
b = 0
i += 1
我想添加另一个变量,如 counter_towards 和 counter_back 并每次添加一个值,但这不能解决我的问题,因为我仍然必须在每次代表时返回这些值。 将相关功能添加到 class 可能会工作,但这需要大量工作,我认为这个问题可能有一个简单的答案。
您必须观看 python 发电机。 这是一个链接!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.