Informatics2-2018/Lab02

A MathWikiből
(Változatok közti eltérés)
(Új oldal, tartalma: „previous up next = Exercises = == List first == Write a python function that retur…”)
 
(Separate)
 
(egy szerkesztő egy közbeeső változata nincs mutatva)
18. sor: 18. sor:
 
== Color code ==
 
== Color code ==
 
The colors on your screen are usually stored as a combination of three components (primary colors): red, green and blue. All components are between 0 and 1 (real numbers).
 
The colors on your screen are usually stored as a combination of three components (primary colors): red, green and blue. All components are between 0 and 1 (real numbers).
This triplet of numbers is the RGB code.
+
This triplet of numbers is the "RGB code".
A leggyakrabban használt módszert RGB kódolásnak hívják, ami a "red", "green" és "blue" szavak kezdőbetűjéből áll össze, mert a szín komponensei ilyenkor a piros, zöld, kék sorrendben vannak megadva.
+
  
Írjunk függvényt ami név alapján ki tudja választani a megfelelő komponenst.
+
Write a function that retrieves a given component from the RGB triplet.
 
+
The function should be named <code>color_code</code>, it should have two parameters:  
A python függvény neve legyen <code>szin_komponens</code>, két paramétere legyen:  
+
* ''color'', a list of three numbers.
* ''szin'', egy három elemű lista, ami a három komponens erősségét tartalmazza három 0 és 1 közötti valós számként
+
* ''component'', a string which is either "red", "green" or "blue"
* ''komponens'', a "piros", "zold" és "kek" karakterláncok egyike
+
* The function should return the corresponding color intensity value.
* A függvény térjen vissza a ''komponens''-nek megfelelő szín komponens erősségével, tehát a lista megfelelő elemével.  
+
  
 
== Perfect numbers ==
 
== Perfect numbers ==
32. sor: 30. sor:
 
Write a function which evaluates whether a number is [https://en.wikipedia.org/wiki/Perfect_number perfect].
 
Write a function which evaluates whether a number is [https://en.wikipedia.org/wiki/Perfect_number perfect].
  
== Sorszámok ==
+
== Race numbers ==
Megvan egy versenyen induló versenyzők listája. Meg akarjuk őket számozni 1-től indulva.
+
We have a list of competitors in a competition and we wish to assign a unique race number to each of them.
 +
The numbers should start from 1 up to the number of competitors.
  
Írjunk függvényt, ami visszaadja a szükséges sorszámok listáját, hogy ki tudjuk a sorszámokat nyomtatni.
+
Write a function that has one parameter: the list of competitors and returns a list of corresponding race numbers.
 
+
The function should be named <code>racenumbers</code>, with one parameter.
A függvény neve legyen <code>sorszamok</code>, egy paramétere legyen: ''indulok'', a versenyzők listája.
+
Ha az ''indulok'' listának N eleme van, akkor a függvény egy olyan listával térjen vissza, ami a számokat 1-től N-ig tartalmazza.
+
 
+
== Naplóból ==
+
Egy gimis tanár úgy szokta eldönteni hogy ki feleljen az óráján, hogy sorsol egy számot ''0'' és az ''osztály létszáma-1'' között, majd az felel aki a naplóban annyiadik helyen van.
+
 
+
Írjunk függvényt ami megmondja hogy ki fog felelni, a diákok listájából, és a sorszámból amit kisorsolt a tanár. Az egyetlen gond hogy a mi listánk nincs névsorba rendezve mint a napló.
+
 
+
A függvény neve legyen <code>naplobol</code>, két paramétere legyen:
+
* ''nevek'', egy lista ami az osztály diákjait tartalmazza, de nincs sorba rendezve
+
* ''sorszam'', egy szám, hogy a sorbarendezett listából hányadikdiák fog felelni. Ha ez a szám 0, akkor a névsorban első fog felelni, és így tovább.
+
 
+
A függvény a felelő nevével térjen vissza.
+
  
 
== Separate ==
 
== Separate ==
  
Let L be a list of numbers, write a function that separates its elements into two lists: one for non-negative and one for positive elements. For example
+
Let L be a list of numbers, write a function that separates its elements into two lists: one for positive and one for non-positive elements. For example
  
 
     L = [-1, 2, 5, -2, 3, -4, -5, 2, -2, 0, 5, 5, 6, 3, -3]
 
     L = [-1, 2, 5, -2, 3, -4, -5, 2, -2, 0, 5, 5, 6, 3, -3]
59. sor: 45. sor:
 
Then the result should be two lists.
 
Then the result should be two lists.
  
== Legnagyobb ==
+
== Argmax ==
Írjunk python függvényt, ami megmondja hogy hányadik egy lista legnagyobb eleme.
+
Write a function that finds the largest value in a list and returns the index of that element.
 
+
A függvény neve legyen <code>legnagyobb</code>, egy paramétere legyen: ''l'', ami egy számokat tartalmazó lista.
+
 
+
A függvény térjen vissza a lista legnagyobb elemének indexével. Például az <code>[3, 2, 1]</code> listára a 0 számot adja, mert a nulladik a legnagyobb.
+
 
+
Ezt a műveletet szokás <code>argmax</code>-nak is nevezni.
+
 
+
== Udvarias ==
+
A bemenetünk egy lista: ''l'', ami női neveket tartalmaz.
+
Alkossunk minden névből egy udvarias megszólítást úgy, hogy elé tesszük hogy "Ms.".
+
Így pl. abból hogy "Alice", legyen "Ms. Alice". Az így módosított listát adjuk vissza visszatérési értékként.
+
 
+
== Szorzó ==
+
 
+
A bemenetünk egy lista: ''l'', ami számokat tartalmaz, és egy szám: ''k''. Adjuk vissza azt a listát, amit úgy kapunk, hogy ''l'' minden elemét megszorozzuk ''k''-val.
+
 
+
== Neptun előbb ==
+
Az egyetemen a különféle számonkérések eredménye sokszor Neptun kód alapján van közölve, nem a név alapján.
+
Ilyenkor, főleg egy hosszú listában, nehéz lehet megkeresni a saját eredményünket.
+
Írjunk egy függvényt, ami megmondja egy Neptun kódok alapján rendezett listában, a mi Neptun kódunk és az éppen látott Neptun kód alapján, hogy a mi sorunk előbb van-e a táblázatban vagy sem.  
+
  
Írjunk python függvényt, neve legyen <code>neptun_elobb</code>, két paramétere legyen:  
+
The function should be called <code>argmax</code>, should have one parameter: ''l'' the list of numbers.
* ''mienk'', a mi Neptun kódunk
+
* ''aktualis'', az éppen most látott Neptun kód.
+
A függvény a speciális <code>True</code> azaz igaz értékkel térjen vissza ha a mi kódunk van előbb, és a <code>False</code>, azaz hamis értékkel, ha később.  
+
  
= Cloudcoder =
+
The function should return the index of the largest element. For example <code>[3, 2, 1]</code> should result 0.
  
# ismetles
+
== Multiply ==
# kiejtes
+
# buvos_negyzet
+
# szorzotabla
+
# pascal
+
# cserebere
+
  
 +
We have two parameters: a list of numbers ''l'' and an additional number ''k''. The output should be a list where every number is ''k'' times the corresponding number in ''l''.
  
 
[[Informatics2-2018/Lab01|previous]] [[Informatics2-2018#Labs|up]] [[Informatics2-2018/Lab03|next]]
 
[[Informatics2-2018/Lab01|previous]] [[Informatics2-2018#Labs|up]] [[Informatics2-2018/Lab03|next]]

A lap jelenlegi, 2018. február 22., 12:38-kori változata

previous up next

Tartalomjegyzék

Exercises

List first

Write a python function that returns the first element of a list, if there is any, and None is the list is empty. The function should be named list_first with one parameter: l, the list. the function should return the first element or a special None value.

List end

Write a function that returns the last part of a list!

The function should be called list_end, with two parameters: l the list and c the number of elements to keep (at the end). If the list is shorter than c then return a None value. Otherwise return the list of the last c elements.

Color code

The colors on your screen are usually stored as a combination of three components (primary colors): red, green and blue. All components are between 0 and 1 (real numbers). This triplet of numbers is the "RGB code".

Write a function that retrieves a given component from the RGB triplet. The function should be named color_code, it should have two parameters:

  • color, a list of three numbers.
  • component, a string which is either "red", "green" or "blue"
  • The function should return the corresponding color intensity value.

Perfect numbers

Write a function which evaluates whether a number is perfect.

Race numbers

We have a list of competitors in a competition and we wish to assign a unique race number to each of them. The numbers should start from 1 up to the number of competitors.

Write a function that has one parameter: the list of competitors and returns a list of corresponding race numbers. The function should be named racenumbers, with one parameter.

Separate

Let L be a list of numbers, write a function that separates its elements into two lists: one for positive and one for non-positive elements. For example

   L = [-1, 2, 5, -2, 3, -4, -5, 2, -2, 0, 5, 5, 6, 3, -3]

Then the result should be two lists.

Argmax

Write a function that finds the largest value in a list and returns the index of that element.

The function should be called argmax, should have one parameter: l the list of numbers.

The function should return the index of the largest element. For example [3, 2, 1] should result 0.

Multiply

We have two parameters: a list of numbers l and an additional number k. The output should be a list where every number is k times the corresponding number in l.

previous up next

Személyes eszközök