目前我有这个功能:
from oracle import Oracle
oracle = Oracle()
import random
def highlow(tolerance):
"""Returns approximation of a randomly generated number between
1-100 to within a given tolerance"""
b = [0, 100]
guess = random.random()*100 # random starting guess
while abs(oracle.reveal() - guess) > tolerance:
if oracle.ask(guess) is True: # guess is less than number
b[0] = guess # guess becomes new lower bound
guess = (guess + b[1])/2 # guess is middle of new range
else: # guess is larger or equal
b[1] = guess # guess becomes new upper bound
guess = (guess + b[0])/2 # guess is middle of new range
return b
在同一个程序中,我想用oracle生成的不同数字运行这个函数3次,我怎么能这样做?
答案 0 :(得分:0)
每次初始化该功能时,您都会再次运行它。你只是这样做:
first_run = highlow(YOUR_NUMBER)
second_run = highlow(ANOTHER_NUMBER)
等等......你需要的。