Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python: A: Write a program even1.py with a function printEven with heading: In y

ID: 3849243 • Letter: P

Question

Python:

A: Write a program even1.py with a function printEven with heading:

In your main program, test the function, calling it several times with different lists of integers. Hint: A number is even if its remainder, when dividing by 2, is 0.

B:

Write a program even2.py with a function chooseEven with heading:

In your main program, test the function, calling it several times with different lists of integers and printing the results. Hint: Create a new list, and append the appropriate numbers to it.

Explanation / Answer

Question A

def printEven(nums):       #even function
for n in nums:
if n % 2 == 0:       #checking for even number
print(n)       #printing the result
print(printEven([4,1,3,2,7]))   #calling the function


Question B

def chooseEven(nums):       #even funciton
even = []
for n in nums:
if n % 2 == 0:       #chdecking for even
even.append(n)   #adding the even no to the list
return even
print(chooseEven([4,1,3,2,7]))   #calling the function