Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I keep getting the answer of not even or odd regardless of which numbers I enter in this program def is_list_even(my_list): x = 0 while
I keep getting the answer of not even or odd regardless of which numbers I enter in this program
def is_list_even(my_list):
x = 0
while x < len(my_list):
if x % 2 != 0:
return False
x= x + 1
return True
def is_list_odd(my_list):
x = 0
while x < len(my_list):
if x % 2 == 0:
return False
x = x + 1
return True
if __name__ == '__main__':
num_Vals = int(input())
input_list = []
for x in range(num_Vals):
input_list.append(num_Vals)
if is_list_even(input_list):
print('all even')
elif is_list_odd(input_list):
print('all odd')
else:
print('not even or odd')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started