## Thursday, June 3, 2021

Solution Exercise 49: Python algorithm that determines the maximum of elements with even index of a given list #### Exercise 49

Write a Python algorithm as a function that takes a list L as a parameter and returns the maximum number of elements with even index without using any predefined functions in Python. Example if L = [13, 2, 31, 120, 4, 97, 15], the algorithm returns the number 31.

#### Solution

``````def maxEven (L):
# initialize the maximum of even index elements
evenMax = L 
# iterate over even index items in the list
for i in range (0, len (L)):
if i% 2 == 0:
# each time that evenMax < L[i] replace evenMax by L[i]
if evenMax <L [i]:
evenMax = L [i]
return evenMax

# Example
L = [13, 2, 31, 120, 4, 97, 15]
print (maxEven (L)) # output:  31``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 