Python
Python
Each
solution should be written in the appropriate function.
~~~
""" I2C Midterm Exam
"""
For example: 2016 is a leap year as it is divisble by 4, but not by 100. 2021
is not a leap year as it is not divisble by 4. 1900 is not also a leap year
as it is divisible by 100 and by 4, but it is not divisible by 400. 2000 is a
leap year as it is divisible by 400.
Your function should return one number, how many leap years have occured
since the given start year. You should NOT return list of leap years.
Ex.:
2021 -> 0 (2021 is not a leap year)
2015 -> 2 (only 2016 and 2020 are leap years)
1899 -> 30
1121 -> 219
"""
def leapYearCount(start_year):
pass
For example, if the list is [1,2,3,4,5], maximum is 5 and the second maximum
is 4.
IF YOU USE `sorted` or `sort` FUNCTION YOU WILL GET ONLY 2 OUT OF 3 POINTS.
Ex.:
[1,2,3,4,5] -> 4
[2,-1,4] -> 2
[-3,4,2,4,1] -> 4
[1,5,2,1,3,3] -> 3
"""
def almostMax(lst):
pass
""" Task #5 (4 points)
Write a function `oddCheck` which takes the list of numbers and checks if
all odd numbers from that list are greater than 15.
You should solve the problem using HOFs: takewhile, dropwhile, zip, filter,
map, reduce, enumerate, any, all, sum, len.
YOU WILL GET 4 POINTS IF YOU SOLVE PROBLEM USING ONLY GIVEN HOFs. OTHERWISE
YOU WILL GET AT MOST 2 POINTS.
Ex.:
[2,17,12,21,101] -> True
[103] -> True
[15] -> False (15 is not greater than 15)
[20] -> True (There are no odd numbers)
[1, 2, 4, 21] -> False (1 is not greater than 15)
"""
def oddCheck(lst):
pass
N = 1 -> 1
N = 2 -> 2 3
12
N = 3 -> 3 4 5
234
123
N = 4 -> 4 5 6 7
3456
2345
1234
Ex.:
1 -> [[1]]
2 -> [[2,3],[1,2]]
3 -> [[3,4,5],[2,3,4],[1,2,3]]
4 -> [[4,5,6,7],[3,4,5,6],[2,3,4,5],[1,2,3,4]]
"""
def diagonalMatrixGenerator(N):
pass