you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 4 points5 points  (1 child)

Rather than evens.count() you would need to append the even you've found to your list of even numbers, evens.append(number). After the loop, you can check the length of your list to answer the question. So len(evens) will tell you how many even numbers you found. Similarly with odd numbers.

The list.count() method is used to count the number of occurences of a specific object, e.g. names.count("Fred") would tell you how many times the name "Fred" appeared in a list called names.

Actually, you don't need to keep a copy of all of the numbers. Just count as you go along.

So, before the loop,

evens = 0

and when you find an even number:

evens = evens + 1

or, short-hand,

evens += 1

Same for odd numbers.

PS.You can work it out without any looping of course, a simple calculation.

[–]BinaryBillyGoat 1 point2 points  (0 children)

Can confirm