How from this time series list = [60, 90, 120, 60, 90, 120, 150] to create the cumulative list_1 = [60, 90, 120, 180, 210, 240] in python?

  Kiến thức lập trình

The data is from a chronometer.
I set the above question to chat gpt but after many tries i couldn’t get what i wanted.A general idea of its scripts is:

time_series = [60, 90, 120, 60, 90, 120, 150]
result = []

# Start by adding the first value
result.append(time_series[0])

i = 1
while i < len(time_series):
    current_value = time_series[i]

    if current_value >= result[-1]:
        # If the current value is greater than or equal to the last value in result, append it
        result.append(current_value)
    else:
        # If the current value is smaller, sum it with the last value in result
        new_value = result[-1] + current_value
        result.append(new_value)
        
        # Move to the next value and skip all smaller or equal values
        while i < len(time_series) and time_series[i] <= current_value:
            i += 1
        
        # Continue with the next value if available
        if i < len(time_series):
            current_value = time_series[i]
            # Append it if it is greater than or equal to the last value in result
            if current_value >= result[-1]:
                result.append(current_value)
    
    # Move to the next index
    i += 1

print("Final Result:", result)

And the output is: Final Result: [60, 90, 120, 180, 300]

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT