Python:帮助创建循环吗?

时间:2018-10-03 15:48:02

标签: python loops for-loop while-loop

我必须循环执行此功能。

我想传递x。 x,表示循环应执行多少次。

关于我的数据越来越长:

def get_data(x):
ts = round(time.time())
url = 'https://api.bitfinex.com/v2/candles/trade:'
timeframe = '1h:'
symbol = 'tBTCUSD'
period = 120 * 3600  # max. 120
start = '/hist?start=' + str((ts - period) * 1000)

end = '&end=' + str(ts * 1000)
string = url + timeframe + symbol + start + end

response = requests.get(string)
data = response.json()

time.sleep(1)

period2 = x * period
start = '/hist?start=' + str((ts - period2 - 3600) * 1000)
end = '&end=' + str((ts - period - 3600) * 1000)
string = url + timeframe + symbol + start + end

response = requests.get(string)
data1 = response.json()

data.extend(data1)
time.sleep(1)

return data

我如何完成此任务?

1 个答案:

答案 0 :(得分:0)

x=0
While x < desired_number_of_loops: 
    do stuff
    x+=1

有关while循环here

的更多信息