samedi 2 octobre 2021

if condition is not working - python program

I want to write progarm, The function accepts two integers n, m as arguments Find the sum of all numbers in range from 1 to m(both inclusive) that are not divisible by n. Return difference between sum of integers not divisible by n with the sum of numbers divisible by n. In my case, if is not working.

n = int(input("num "))
m = int(input("limit "))
for i in range(1, m+1):
    sum1 = 0
    sum2 = 0
    if i % n == 0:
        sum1 += i
    else:
        sum2 += i
print(f"{sum1} and {sum2}")
print(abs(sum2-sum1))

Aucun commentaire:

Enregistrer un commentaire