0

# FreeStuff! python core 26.5 practice.. help

So for this exercise we get: items = [23, 555, 666, 123, 128, 4242, 990] sum = 0 n = 0 while n < len(items): num = items[n] n += 1 sum += num print (sum) we are then asked to change the code in the appropriate way to ignore any odd numbers and output the sum off the even numbers. In the help at the bottom of the exercise we are asked to use the continue statement to skip loop iterations. any suggestions?

27th Aug 2021, 9:33 AM
Luke Parry + 1
items = [23,555,666,123,128,4242,990] sum = 0 n = 0 while n < len(items): num = items [n] n += 1 if num %2 == 0: sum += num else: continue print (sum) This is how you use it in a while loop where is the other guy shows you a for Loop however if you play with this for a second you'll also notice that if you release the else statement and run the code without it it runs the same this particular example as far as I am able to figure out doesn't actually need the continue statement in order to work correctly
14th Oct 2021, 8:54 PM
Devery Mcneely + 1
items = [23,555,666,123,128,4242,990] sum = 0 n = 0 while n < len(items): num = items [n] n += 1 if num %2 == 1: continue else: sum += num print (sum) This is how I believe that the assignment is to be completed instead of saying what's divisible by 2 with a remainder of 0 what I want to do is say if the number is odd skip go back can only add the ones that are even
14th Oct 2021, 9:02 PM
Devery Mcneely 0
You can use condition to check type of number items = [23, 555, 666, 123, 128, 4242, 990] sum = 0 for num in items: If num % 2==0: sum += num else: continue print (sum)
27th Aug 2021, 9:47 AM  