517,866 views
42 votes
42 votes
6.25 lab: even/odd values in a vector 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 that follow. ex: if the input is:

User Schudel
by
2.7k points

1 Answer

21 votes
21 votes

def is_list_even(my_list):

for i in my_list:

if(i%2 != 0):

return False

return True

def is_list_odd(my_list):

for i in my_list:

if(i%2 == 0):

return False

return True

def main():

n = int(input())

lst = []

for i in range(n):

lst.append(int(input()))

if(is_list_even(lst)):

print('all even')

elif(is_list_odd(lst)):

print('all odd')

else:

print('not even or odd')

if __name__ == '__main__':

main()

User Nicoleta
by
2.6k points