HUN
3/1. advanced_indexing
Írjunk függvényt,
aminek bemenete egy lista és egy
indexek listája:- lista: egy lista
- indexek:
nem-negatív egészek listája
Kimenetként a lista azon
elemeit adjuk vissza, amely indexek a második listában szerepeltek
Például
ha indexek=[0, 1, 0] akkor egy három elemű listát kell
visszaadni,aminek elemei rendre a lista nulladik, első
és ismét a nulladik elemei.
Az indexek között nem
lesz olyan, ami kívül esne az első lista indexein.
3/2. matrix_sum
Írjunk függvényt mely a bementi M1 és M2
mátrixoknak visszaadja az összegét. Ha a mátrixok nem adhatók
össze, akkor üreslistával tér vissza.
Például a következõ
függvényhívásra:
A = [[1, 2, 3], [4, 5,
6]]
B = [[1, 1, 1], [1, 1, 1]]
matrix_sum(A,
B)
ezt a mátrixot adja vissza: [[2,
3, 4], [5, 6, 7]]
3/3. divisor_dict
Egy nagyobb programban amin dolgozunk,
bizonyos
számok kisebb osztóinak a listájára gyakran szükség van. Ezért
nem szeretnénk mindig újra kiszámolni az osztók listáját amikor
kell, hanem ezekre a gyakran előforduló számokra kiszámolnánk
egyszer előre, és mindegyik számhoz letárolnánk az osztói
listáját egy szótárba.
Az divisor_dict nevű
függvény paramétere - l, a vizsgálandó egész
számok listája
A függvény egy szótárral kéne hogy visszatérjen,
amiben kulcsként szerepel l-ből minden szám, és mindhez
a nála kisebb osztóinak a nagyság szerint növekvő listája
van rendelve.
Például az l=[3,10,12]
esetén a következőt kell kapnunk:
{3: [1], 10: [1,2,5], 12: [1,2,3,4,6] }
3/4. midterm_result
Írjunk egy függvényt, ami jegyre váltja a ZH pontunkat. - a
függvény neve legyen midterm_result
- két paramétere
legyen: pont és hatarok
- a pont
egy nem-negatív egész szám, az elért pontszám
- a hatarok
pedig egy szótár, ahol a kulcsok a jegyek, az értékek pedig az
adott érdemjegynek az alsó ponthatára
- a függvény adja vissza,
hogy az adott pont milyen érdemjegyet jelent (1-5) az adott ponthatárok
fényében.
Például az infó ZH-ban a ponthatárok ezek lennének: {2:50,3:60,4:70,5:80}
Az
egyesnek nincsen külön ponthatára, mert a kettes alatti mindig
automatikusan 1-es (nullást nem lehet kapni). És az 5-ös alsó
határa felett minden pont 5-ösnek számít.Figyelem
A ponthatárok <=
relációban számítanak, vagyis ha valaki pont az alsó ponthatáron
van, akkor még megkapja az adott jegyet.
ENG
3/1. advanced_indexing
Write
a function with two parameters:- L: a list if
items
- indices: a list of non-negative integers
The
output should be the elements from the first list according to
the indices.
For example if indices=[0, 1, 0] then
you should return a three element listcontaining the zeroth,
first and zeroth elements of the original list.
The parameter indices
won't contain bigger indices than the maximum index in L.
3/2. matrix_sum
Write a function
with two input parameters: M1 and M2,those are
arrays: list of list of numbers.Return the sum of the matrices
if they are compatible, or an empty list otherwise.
For
example:
A = [[1, 2, 3], [4, 5, 6]]
B = [[1, 1, 1], [1, 1, 1]]
matrix_sum(A, B)
You
get: [[2, 3, 4], [5, 6, 7]]
3/3. divisor_dict
In a program one needs to calculate a lots
of divisors.What you want to do is to store the already calculated
divisors.To this end you have to make a dictionary of numbers
and their divisors.
There is a code
which does something similar, but it is working incorrectly,
you have to fix it!
The function called divisor_dict
and has one argument: - l, list of the numbers
in question.
The function should return a dictionary,
where the keys are theinput numbers and their values are the
sorted list of their divisors (not including the number itself).
For
example is l=[3,10,12]
then the result should be
{3: [1], 10: [1,2,5], 12: [1,2,3,4,6] }
3/4. midterm_result
Write a function
that converts your midterm points into grades. - the function
should be named midterm_result
- with two parameters: point
and limits
- the point is a non-negative
integer, the points on the midterm
- the limits is
a dictionary where the keys are the grades and the values are
the lower bound for the given grade.
- the function should
return the earned grade (1-5) with respect to the given limits
For
example in Informatics the limits are: {2:50,3:60,4:70,5:80}
The
worst grade doesn't have a lower bound, because everything under
the lower bound of 2 worth 1. You cannot get a 0 grade. And everything
above the limit of 5 is a 5.Hint
The lower bounds should
compare as <= since reaching the limit exactly still
worth the grade.