indexLargestEvenInt should return the index
in the list of the largest even integer. If there
are no even integers in the list, it should return
None.
1
2
3
4
5
6
7
8
9
10
11
12
deftest_1():# 88 is at index 2
assertindexLargestEvenInt([22,55,88,33,66])==2deftest_2():# there are no even ints
assertindexLargestEvenInt([33,11,77])==Nonedeftest_3():# 66 is at index 3
assertindexLargestEvenInt([33,34,11,66,99])==3deftest_4():# 44 is at index 0
assertindexLargestEvenInt([44,11,22])==0
Code for indexLargestEvenInt_a
1
2
3
4
5
6
7
8
9
10
defindexLargestEvenInt_a(ilist):"index of largest even integer; None if no even ints"iftype(ilist)!=list:raiseValueError("not a list")answer=Noneforxinilist:ifx%2==0:ifanswer==Noneorx>answer:answer=xreturnanswer
Code for indexLargestEvenInt_b
1
2
3
4
5
6
7
8
9
defindexLargestEvenInt_b(ilist):iftype(ilist)!=list:raiseValueError("not a list")answer=Noneforiinrange(len(ilist)):ifilist[i]%2==0:ifanswer==Noneorilist[i]>ilist[answer]:answer=ireturnanswer
Midterm Handout B for CS8, Final Exam, S18, Page 2
Code for indexLargestEvenInt_c
1
2
3
4
5
6
7
8
9
10
defindexLargestEvenInt_c(ilist):iftype(ilist)!=list:raiseValueError("not a list")answer=Noneforiinrange(len(ilist)):ifilist[i]%2==0:ifanswer==Noneorilist[i]>ilist[answer]:answer=ireturnanswer
Code for indexLargestEvenInt_d
1
2
3
4
5
6
7
8
9
defindexLargestEvenInt_d(ilist):iftype(ilist)!=list:raiseValueError("not a list")answer=Noneforxinilist:if(x%2==0)andx>answer:answer=xreturnanswer