With Python 3.8 and later, you can use :=
(walrus operator/ walrus operator) to write:
num1 = 0
_ = [print(x-(num1:=num1+i)) for in num]
An implementation using itertools.accumulate()
is likely.Please adjust the print output separately, as the calculation results can be obtained as a list.
import it tools
x,n = map(int, input().split())
num = [int(input()) for_in range(n)]
z = [x-n for n intertools.accumulate(num)]
print(z)
© 2024 OneMinuteCode. All rights reserved.