0

Can some explain this code in python. I think I'm misunderstanding the use of the modulous symbol.

nums = [55, 44, 33, 22, 11] if any([i % 2 == 0 for i in nums]): print("At least one is even")

8th Apr 2020, 5:20 PM
Paul Rethier
Paul Rethier - avatar
4 odpowiedzi
0
Modulus functions work is to output the remainder. Eg| - 5%2 =would give 1 because 2*2 =4 and the remainder remains 1. Now I think you might be able to understand the code better. Try and if you still don't understand then comment.
8th Apr 2020, 5:23 PM
Akash
Akash - avatar
0
Is i representing each number in the list?
8th Apr 2020, 5:29 PM
Paul Rethier
Paul Rethier - avatar
0
Paul Rethier Yes, i represents each number in turn Maybe you should familiarise yourself with 'list comprehensions' as that appears to be where your issue is.
8th Apr 2020, 5:42 PM
Russ
Russ - avatar
0
That's the section I'm working on. I just wasn't understanding what I represented in that code and kept getting the answer wrong. I appreciate the help.
8th Apr 2020, 5:47 PM
Paul Rethier
Paul Rethier - avatar