Assignment 1 - Problem 3

Can anyone explain this? I really confused.

The first one i copied from other people, and the rest i wrote them myself

What do you want explained?

For loops, if statement?

What the condition is doing?

Or is there some part you want explained?

Why my 2nd, 3rd, and 4th coding have different print than the correct one (1st), even though it is the same coding. I’m trying to wrote it back but got different result. I’m so confused.

Maybe because you are using condition with i

for i in range(18,354):
    if(i%7==0):

But updating, your sum_of_numbers with 1 instead of i.

# In cases 2nd, 3rd, and 4th you are doing
sum_of_numbers += 1

# In 1st case it is 
# sum_of_numbers += i

So, in your code every time i%7 == 0 is satisfied it updates sum_of_numbers with 1 instead of i, which is what happens in the 1st case.

Thank you so much for your help

what is the solution for problem 3 of assignment 1…?

Can you post a screenshot or link for the question and the error you are getting?

Use a for loop with range function to select the value between 18 and 534 i.e. range(18,534)

Use if statement like
If value % 7 = 0:
sum_of_numbers = sum_of_numbers + value