【问题标题】:Python: Help to create a loop?Python:帮助创建循环?
【发布时间】:2018-10-03 15:48:02
【问题描述】:

我必须循环执行此功能。

我想通过 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

我怎样才能完成这项任务?

【问题讨论】:

  • 有什么问题?你在哪里遇到麻烦了?
  • 欢迎来到 SO!你能正确缩进你的代码吗?使用四个空格。我自己搞不清楚函数边界在哪里。

标签: python loops for-loop while-loop


【解决方案1】:
x=0
While x < desired_number_of_loops: 
    do stuff
    x+=1

更多关于while循环here

【讨论】:

    猜你喜欢
    • 2021-02-08
    • 1970-01-01
    • 2010-11-21
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 2015-07-30
    相关资源
    最近更新 更多