JustCaptain kod-buduschego
fe9c6c08be73ce67e8771ed2945bb1d512df3ae4
Перейти к файлу
Код
kod-buduschego Python 2025-20262.5. Цикл Whilepracticeschatgpt2task_4.py
anc update c70a58f 8 октября 2026 г.
task_4.py
import time 
start = time.time()
profits = [500, -200, 700, -150, 300, -500, 300, -400, -400] * 1000
index: int = len(profits) - 1 # 9 - 1 = 8
while index != -1:
    if profits[index] < 0:
        profits.pop(index)
    index -= 1
# print(profits)
print(time.time() - start)


start = time.time()
profits_two = [500, -200, 700, -150, 300, -500, 300, -400, -400] * 1000
index_two: int = 0
while index_two != len(profits_two):
    if profits_two[index_two] < 0:
        profits_two.pop(index_two)
    else:
        index_two = index_two + 1
# print(profits_two)
print(time.time() - start)