Issue
Provided is a list of numbers. For each of the numbers in the list, determine whether they are odd. If the number is odd, add True to a new list called is_odd. If the number is even, then add False
num_lst = [3, 20, -1, 9, 10]
def odd(x):
return x % 2 != 0
print(odd(num_lst))
Solution
This can be done with a simple for loop:
num_list = [3, 20, -1, 9, 10]
is_odd = []
def odd(x):
return x % 2 != 0
for num in num_list:
is_odd.append(odd(num))
print(is_odd)
Answered By - disarray
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.