Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers in the list. The first integer is not in the list. Your program must define and call the following two functions. is_list_even() returns true if all integers in the list are even and false otherwise. is_list_odd() returns true if all integers in the list are odd and false otherwise. def is_list_even(my_list) def is_list_odd(my_list)
Write a
Your program must define and call the following two functions. is_list_even() returns true if all integers in the list are even and false otherwise. is_list_odd() returns true if all integers in the list are odd and false otherwise.
def is_list_even(my_list)
def is_list_odd(my_list)
My program is failing on is_list_even([10,12,14]) and
is_list_odd([9,11,13])
Code so far:
def is_list_even(my_list):
for i in range(len(my_list)):
if my_list[i] % 2 != 0:
return False
return True
def is_list_odd(my_list):
for i in range(len(my_list)):
if my_list[i] % 2 == 0:
return False
return True
if __name__ == '__main__':
my_list = []
n = float(input())
for i in range(n):
my_list.append(float(input()))
if is_list_even(my_list):
print("all even")
elif is_list_odd(my_list):
print("all odd")
else:
print("not even or odd")
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images