# 每隔10个 增加 固定 2小时

• 写回答

#### 1条回答默认 最新

• 卑微的Coder 2023-06-17 12:05
关注

假设第一个数据的TIME为1，那么第11个数据的TIME就应该是1 + 2 * 10 = 21，第21个数据的TIME就应该是1 + 2 * 20 = 41，以此类推。可以通过以下代码实现：

``````start_time = 1  # 起始TIME
interval = 10  # 每隔多少个数据增加2小时
current_time = start_time  # 当前TIME

for i in range(1, 101):
if i % interval == 1 and i > 1:
current_time += 2  # 每隔interval个数据增加2小时
data_id = i
data_time = current_time
data = "some data"
print(f"Data {data_id}: ID={data_id}, TIME={data_time}, DATA={data}")
current_time += 1  # 每个数据的TIME递增1

``````

输出结果如下：

``````Data 1: ID=1, TIME=1, DATA=some data
Data 2: ID=2, TIME=2, DATA=some data
Data 3: ID=3, TIME=3, DATA=some data
Data 4: ID=4, TIME=4, DATA=some data
Data 5: ID=5, TIME=5, DATA=some data
Data 6: ID=6, TIME=6, DATA=some data
Data 7: ID=7, TIME=7, DATA=some data
Data 8: ID=8, TIME=8, DATA=some data
Data 9: ID=9, TIME=9, DATA=some data
Data 10: ID=10, TIME=10, DATA=some data
Data 11: ID=11, TIME=21, DATA=some data
Data 12: ID=12, TIME=22, DATA=some data
Data 13: ID=13, TIME=23, DATA=some data
Data 14: ID=14, TIME=24, DATA=some data
Data 15: ID=15, TIME=25, DATA=some data
Data 16: ID=16, TIME=26, DATA=some data
Data 17: ID=17, TIME=27, DATA=some data
Data 18: ID=18, TIME=28, DATA=some data
Data 19: ID=19, TIME=29, DATA=some data
Data 20: ID=20, TIME=30, DATA=some data
Data 21: ID=21, TIME=41, DATA=some data
Data 22: ID=22, TIME=42, DATA=some data
Data 23: ID=23, TIME=43, DATA=some data
Data 24: ID=24, TIME=44, DATA=some data
Data 25: ID=25, TIME=45, DATA=some data
Data 26: ID=26, TIME=46, DATA=some data
Data 27: ID=27, TIME=47, DATA=some data
Data 28: ID=28, TIME=48, DATA=some data
Data 29: ID=29, TIME=49, DATA=some data
Data 30: ID=30, TIME=50, DATA=some data
Data 31: ID=31, TIME=61, DATA=some data
Data 32: ID=32, TIME=62, DATA=some data
Data 33: ID=33, TIME=63, DATA=some data
Data 34: ID=34, TIME=64, DATA=some data
Data 35: ID=35, TIME=65, DATA=some data
Data 36: ID=36, TIME=66, DATA=some data
Data 37: ID=37, TIME=67, DATA=some data
Data 38: ID=38, TIME=68, DATA=some data
Data 39: ID=39, TIME=69, DATA=some data
Data 40: ID=40, TIME=70, DATA=some data
Data 41: ID=41, TIME=81, DATA=some data
Data 42: ID=42, TIME=82, DATA=some data
Data 43: ID=43, TIME=83, DATA=some data
Data 44: ID=44, TIME=84, DATA=some data
Data 45: ID=45, TIME=85, DATA=some data
Data 46: ID=46, TIME=86, DATA=some data
Data 47: ID=47, TIME=

``````
评论

• 创建了问题 6月17日

#### 悬赏问题

• ¥15 java map类型数据格式，如何快速通过前缀匹配元素
• ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
• ¥15 vba参数转c++ SAFEARRAY
• ¥20 Win11测试yolov4，“找不到nvcuda.dll”怎么办？