Computers and Technology

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:

5
2
4
6
8
10
the output is:

all even
Ex: If the input is:

5
1
3
5
7
9
the output is:

all odd
Ex: If the input is:

5
1
2
3
4
5
the output is:

not even or odd
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 Current Code:

def GetUserValues():
myList=[]
n=int(input())
for i in range(n):
myList. append(int(input()))
return myList

def IsListEven(myList):
for i in range(len(myList)):
if myList[i]%2 !=0:
return False
return True

def IsListOdd(myList):
for i in range(len(myList)):
if myList[i]%2==0:
return False
return True

list=GetUserValues()
if IsListOdd(list)==True:
print("all odd")
elif IsListEven(list)==True:
print("all even")
else:
print("not even or odd")

What my output was that I need to be solved:

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:20, ashcormu11
Write a program called assignment3 (saved in a file assignment3.java) that computes the greatest common divisor of two given integers. one of the oldest numerical algorithms was described by the greek mathematician, euclid, in 300 b. c. it is a simple but very e↵ective algorithm that computes the greatest common divisor of two given integers. for instance, given integers 24 and 18, the greatest common divisor is 6, because 6 is the largest integer that divides evenly into both 24 and 18. we will denote the greatest common divisor of x and y as gcd(x, y). the algorithm is based on the clever idea that the gcd(x, y) = gcd(x ! y, y) if x > = y and gcd(x, y) = gcd(x, y ! x) if x < y. the algorithm consists of a series of steps (loop iterations) where the “larger” integer is replaced by the di↵erence of the larger and smaller integer. this continues until the two values are equal. that is then the gcd.
Answers: 3
image
Computers and Technology, 22.06.2019 22:30, Metlife
You are new to microsoft certification and want to start out by getting a certification geared around windows 8. what microsoft certification should you pursue?
Answers: 1
image
Computers and Technology, 25.06.2019 08:20, Maxwell2539
The process of representing data in digital form so it can be used by a digital computer is called decimal byterepresentation. - true or false
Answers: 3
image
Computers and Technology, 25.06.2019 12:00, gardinerr410
What is the difference between paper size and page margins in word
Answers: 1
Do you know the correct answer?
Write a program that reads a list of integers, and outputs whether the list contains all even number...

Questions in other subjects:

Konu
Mathematics, 19.10.2020 20:01