我有一个函数,它返回True或False。我正在尝试执行一个循环,在这个循环中调用该函数几次,直到它返回False为止,并计算它运行了多少次。
import random as rand
def test_function():
return rand.random > 0.5
count = 0
while test_function():
count += 1
print count不过,这只是运行了一次,并保存了它得到的任何价值。
发布于 2014-02-14 18:23:42
您必须使用()调用该函数。
return rand.random() > 0.5https://stackoverflow.com/questions/21786740
复制相似问题