Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 207

python function definition to find if all values in a list are even odd or neither [closed]

$
0
0

I am struggling in a college beginner's computer science course and just need simple homework help.

Now, we are currently working on function definitions, and I have to 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 (it just tells the length of the list).

My program must define and call the following two functions. def is_list_even() returns true if all integers in the list are even and false otherwise. def is_list_odd() returns true if all integers in the list are odd and false otherwise. If the list is all even I also have to print 'all even'. If the list is odd, I must print 'all odd'. If the list has both, I must print 'not even or odd'.

I have been able to get all of the integers I need into the list, however the definitions are what I am struggling with (formatting, returning it, etc.). I have pasted the code I have so far below (this website has changed the format of it) but my program produces no output. Any help would be appreciated. Thank you.

n = int(input())my_list =[]for i in range(n):    num = int(input())    my_list.append(num)def IsListEven(my_list):    for i in range(len(my_list)):        if my_list[i] % 2 == 0:            return True        else:            return Falsedef IsListOdd(my_list):    for i in range(len(my_list)):        if my_list[i] % 2 == 1:            return True        else:            return Falsedef GetUserValues():    if IsListOdd(my_list) == True:        print("all odd")    elif IsListEven(my_list) == True:        print("all Even")    else:        print("not even or odd")

Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>