diff --git a/pisomka/testovanie.py b/pisomka/testovanie.py new file mode 100644 index 0000000..5612903 --- /dev/null +++ b/pisomka/testovanie.py @@ -0,0 +1,52 @@ +def pocet_samohlasok(text): + samohlasky = "aeyuio" + counter = 0 + for i in text.lower(): + if i in samohlasky: + counter +=1 + return counter + +def najdlhsie_slovo(veta): + slova = veta.split() + najdlshie = "" + for slovo in slova: + if len(slovo) > len(najdlshie): + najdlshie = slovo + return najdlshie + +def striedaj_velkost(text): + result = "" + for i, znak in enumerate(text): + if i % 2 == 0: + result.append(znak.upper()) + else: + result.append(znak.lower()) + return result + +def sucet_parnych(cisla): + parni = [] + for cislo in cisla: + if cislo % 2 == 0: + parni.append(cislo) + suma = sum(parni) + return suma + + + +def bez_duplikatov(cisla): + duplikaty = [] + for cislo in cisla: + if cislo not in duplikaty: + duplikaty.append(cislo) + return duplikaty + +def frekvencia(text): + vysledok = {} + for znak in text: + if znak in vysledok: + vysledok[znak] +=1 + else: + vysledok[znak] = 1 + return vysledok + + diff --git a/u1/two_fer.py b/u1/two_fer.py index 973818f..ddd4535 100644 --- a/u1/two_fer.py +++ b/u1/two_fer.py @@ -1,4 +1,5 @@ def two_fer(name ='teba'): if not name: name = 'teba' - return f'Jeden pre {name}, jeden pre mňa \ No newline at end of file + return f'Jeden pre {name}, jeden pre mňa' +print(two_fer("Janka")) \ No newline at end of file diff --git a/u7/hash_table.py b/u7/hash_table.py new file mode 100644 index 0000000..a91a272 --- /dev/null +++ b/u7/hash_table.py @@ -0,0 +1,19 @@ +class HashTable: + def __init__(self, capacity=10): + if type(capacity) is not int: + raise TypeError("Kapacita musí byť celé číslo (int)") + if capacity <= 0: + raise ValueError("Kapacita musí byť kladné číslo") + self.__capacity = capacity + self._size = 0 + + self.empty = object() + self.deleted = object() + self.slots = [self.empty] * self.__capacity + + @property + def capacity(self): + return self.__capacity + def _check_key(self, key): + if not isinstance(key, str): + raise TypeError("Kľúč musí byť reťazec (str)") \ No newline at end of file