This code had a few mistakes i have fixed some but im stuck on a section

im stuck on “for i in loop” here is the code:

rangeLow  = int(input("What is the lowest number you'd like to add? (inclusive) " ))
rangeHigh = int(input("What is the highest number you'd like to add? (exclusive) " ))
rangeSum  = 0

while (rangeLow < 0):
    print("My minimum is 0 - please try again.")
    rangeLow  = int(input("What is the lowest number you'd like to add? (inclusive) "))


while (rangeHigh > 1000):
    print ("My maximum is 1000 - please try again.")
    rangeHigh = int(input("What is the highest number you'd like to add? (exclusive) "))

if (rangeLow >= rangeHigh):
    print ("The High number must be larger than Low number. I'll swap these for you.")
    temp = rangeHigh
    rangeHigh = rangeLow
    rangeLow = temp

for i in loop(rangeHigh, rangeLow):
    if (i % 2 == 0):
        print("  Adding " + str(i) + " to the sum.")
        rangeSum = rangeSum + i

    elif (i > rangeHigh):
        print ("My loop has gone past the High number! This shouldn't happen!")

print("The sum of the even numbers from [" + str(rangeLow) + "] to [" + str(rangeHigh) + "] is: " + str(rangeSum))

Use range(rangeLow, rangeHigh) not “loop”.

i did that then reran it and this is what it comes up with:

What is the lowest number you’d like to add? (inclusive) 1
What is the highest number you’d like to add? (exclusive) 6
Adding 6 to the sum.
The sum of the even numbers from [1] to [6] is: 6

shouldn’t the sum be 3?

How did you get the answer 3?

Should sum of even numbers ever be odd?

1 Like

Numbers between 1 (inclusive) and 6 (exclusive): 1, 2, 3, 4, 5

Even numbers between 1 (inclusive) and 6 (exclusive): 2, 4

When I was in school, 2+4 = 6. If that’s changed, I’m going to be very annoyed.

2 Likes

thanks I’m a bit special sometimes haha