#3052
Up
0
Down
::
    `
def calculator(n, m, li):
    print("Your list: ", li)
    for i in range(0, n//m):
        z1 = sum(li[0 + i*m : (i+1)*m])
        x.append(z1)
    if n%m != 0:
        z2 = sum(li[(n//m)*m : ])
        x.append(z2)
    print("list of summations: ", x)
    z3 = len(x)
    res = 0
    for i in range(0, z3):
        res += ((-1)**i) * x[i]
    print("List's final value: ", res)

flag = True

while(flag):
    x = []
    n = int(input("Enter n: "))
    m = int(input("Enter m: "))
    li = list(map(int, input("Enter your list numbers separated by space: ").split()))

    if n < 2: print("n (lenght of list) must be at least 2. Try again! ") flag = False elif m >= n:
        print("m must be less than n. Try again!")
        flag = False
    elif len(li) != n:
        print("Please enter exactly ", n, " elements for your list, separated by 1 space. Try again!")
        flag = False
    else:
        calculator(n, m, li)

    if flag == True:
        resp = input("Do you want to continue (Yes or No)?: ")
    if resp.upper() == "NO" or resp.upper() == "N":
        flag = False
`


پیمایش به بالا