# Asgmnt -1 : problem 3 (zero to pandas)

hi all. I’m doing course in Python(zero to pandas), In my 1st assignment submission I got remarks with "Problem 3 - Conditions and loops ". Saying that the total sum is wrong for me. could any one help me with this. I got total sum of “47460”.

# NUM LIST by increment of 7,in range(21,532)

a = 14
b = []
for i in range (a,533):
a += 7
if a<= 532:
b.append(a)
print(b)

# num list divisible by 7 between 18

d=[]
for i in b:
for j in range (7,19):
c = i%j
if c == 0:
d.append(i)

# num list divisible by 534

for i in b:
if i == 534:
e = i%534
d.append(e)

print(’\n num list divisible by 7 between 18 and 534 :’,d)

# sum of all the numbers divisible by 7 between 18 and 534

result = 0

for k in range(0,len(d)):
result = result + d[k]

print( ‘\n sum_of_numbers :’,result )

Hey @214-balaji
Welcome to Coding…

As you can see, there is a hint given in the question…

Hint: One way to do this is to loop over a `range` using `for` and use an `if` statement inside it.

So, there would be a very easy approach and you don’t have to take use such a long method which btw is hard to debug ( find errors )…

so the simple approach would go something like this…

## Just follow the hint and you don’t event need to read the code

I will solve the question according to the original template given in the assignment…Hope you will understand…

So, as you can see a variable `sum_of_numbers = 0` is set and we begin the `for loop` from 18 to 534 + 1
+1 is there is because for loop goes from `start_pos to end_pos - 1` so instead of 543 + 1 you can also use 535

Now inside the `for loop` there is a condition that `if number is divisible by 7` then continue…
So, only the number which are divisible by 7 will pass this condition and will be added to sum_of_numbers and you will get your results…

Hope You understand…
Thank You…

P.S.
I have noticed that you have multiple copies of same notebooks in your profile…
If you want you can delete all other copies and maybe next time just save the original notebook multiple times instead of creating copies…It will declutter your work environment…
Thanks Once again…

U can also use a while loop to get it with an if statement inside
While I < 5…
Then u check if the number is a module of i

Thank you on your suggestion. I will change accordingly. I was inactive quite few days. I get to see your message just now, It was helpful. Sure I will delete those multiple assignment copies.

Hi @fidekg123,

Thank you on your suggestion. I will change accordingly. I was inactive quite few days. I get to see your message just now, It was helpful.