0% found this document useful (0 votes)
98 views

CYB 130 Week 4 Python LAB 5.24 Even/odd Values in A List: To Buy The Tutorial Please Visit

The document contains Python code to check if all values in a user-input list are even or odd. It defines functions to get a list of values from the user, check if all values in a given list are even, and check if all are odd. The main function calls these functions to check the input list and print the result.

Uploaded by

CHRIS D
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

CYB 130 Week 4 Python LAB 5.24 Even/odd Values in A List: To Buy The Tutorial Please Visit

The document contains Python code to check if all values in a user-input list are even or odd. It defines functions to get a list of values from the user, check if all values in a given list are even, and check if all are odd. The main function calls these functions to check the input list and print the result.

Uploaded by

CHRIS D
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CYB 130 Week 4 Python LAB 5.

24 Even/odd
values in a list

To Buy the Tutorial please visit

def get_user_values():
n = int(input())

lst = []

for I in range(n):

lst.append(int(input()))

return lst

def is_list_even(my_list):

for num in my_list:

in the event that num % 2 == 1:


return False

bring True back

def is_list_odd(my_list):

for num in my_list:

in the event that num % 2 == 0:

return False

bring True back

on the off chance that __name__ == '__main__':


lst = get_user_values()

on the off chance that is_list_even(lst):

print("all even")

elifis_list_odd(lst):

print("all odd")

else:

print("not even or odd")

Code 2
#define is_list_even work that takes list return valid if all
components are even else return bogus

def is_list_even(my_list):

for I in my_list:#for each component of rundown

in the event that i%2!=0:#check number is even or not

return False#return False if any of number isn't even

bring True back

#define is_list_odd work that takes list return valid if all


components are odd else return bogus

def is_list_odd(my_list):
for I in my_list:#for each component of rundown

on the off chance that i%2==0:#check number is odd or not

return False#return False if any of number isn't odd

bring True back

on the off chance that __name__ =='__main__':

a=[]

n=int(input())#Getting size of rundown

for I in range(n):#for each component add it to list


a.append(int(input()))

on the off chance that (is_list_even(a)==True):

print ("all even")#print all in any event, when is_list_even


technique brings valid back

elif (is_list_odd(a)==True):

print ("all odd")#print all odd when is_list_odd strategy brings


valid back

else:

print ("not even or odd")#print this for different cases

Code 3
def GetUserValues():

myList = []

s = input()

while(s):

myList.append(int(s))

You might also like