Compare commits
2 Commits
1739831c8c
...
51f6fe01f9
Author | SHA1 | Date |
---|---|---|
Dawid J. Kubis | 51f6fe01f9 | 3 years ago |
Dawid J. Kubis | f0ff9238e6 | 4 years ago |
@ -1,16 +0,0 @@
|
||||
# kricici_lukas.py
|
||||
```python
|
||||
|
||||
# ptame se uzivatel jestli lukas krici
|
||||
krici = input('Krici Lukas? : ')
|
||||
# promenna `krici` ma typ str
|
||||
|
||||
# zjistujeme jestli uzivatel napsal ano
|
||||
# tady je rozdil mezi 'ano' a 'Ano' (velka pismena nemame osetrena)
|
||||
if krici == 'ano':
|
||||
print('Lukasi, mohl by ses trochu ztisit?')
|
||||
else:
|
||||
print('zrovna nemluvi?')
|
||||
|
||||
# btw tohle vymyslel Lada
|
||||
```
|
@ -1,22 +0,0 @@
|
||||
# sude_nebo_liche.py
|
||||
```python
|
||||
|
||||
# zjistujeme cislo od uzivatele
|
||||
x = input('zadej cislo : ') # x je typ str
|
||||
# prevadime x na typ int pomoci funkce `int`
|
||||
# tohle vyhodi chybu pokud uzivatel je dement
|
||||
# a napsal neco ve smyslu 'ahoj'; to totiz nelze prevest na int
|
||||
x = int(x)
|
||||
|
||||
# koukame se jestli zbytek z deleni dvemi je 0
|
||||
# -> jesli je `x` delitelne dvemi
|
||||
if x % 2 == 0:
|
||||
print('je sude')
|
||||
else:
|
||||
# tohle je sice ekvivalent `elif x % 2 == 1`
|
||||
# ale takhle je to prehlednejsi
|
||||
# mohli bychom taky napsat dalsi if
|
||||
# - fungovalo by to stejne ale tohle je
|
||||
# mnohem prehlednejsi
|
||||
print('je liche')
|
||||
```
|
@ -1,39 +0,0 @@
|
||||
# umocnovani.py
|
||||
```python
|
||||
|
||||
# takze tohle je implementace
|
||||
# skriptu ktery umocnuje cisla
|
||||
# bez pouziti operatoru `**`
|
||||
# je to uprimne trochu gay a
|
||||
# ve skutecnosti byste tohle nikdy
|
||||
# nepouzili, ale hezky to ukazuje praci
|
||||
# s loopama
|
||||
|
||||
# ziskame zaklad
|
||||
a = int(input("zadejte zaklad : "))
|
||||
# ziskame exponent
|
||||
e = int(input("zadejte exponent : "))
|
||||
|
||||
i = 0 # tohle je iteracni promenna
|
||||
# budeme totiz loopovat tolikrat, kolik mame exponent
|
||||
# coz je trochu problem protoze exponent musi
|
||||
# byt cele cislo
|
||||
# no nic
|
||||
|
||||
prod = 1 # do tyhle promenny to budeme vsechno nasobit
|
||||
# pozor; nemuze byt 0 protoze by nula je nulovy prvek
|
||||
# grupy celych cisel s nasobenim; to je jedno
|
||||
# proste by nam pohltila cely nasobeni a vysledek
|
||||
# by byl nula
|
||||
|
||||
while i < e: # loopujeme tolikrat kolik je exponent
|
||||
|
||||
prod *= a # nasobime cislo samym sebou
|
||||
# ekvivalent
|
||||
# prod = prod * a
|
||||
|
||||
i += 1 # pricitame iterator aby to fungovalo
|
||||
|
||||
# vypisujeme vysledek
|
||||
print(f"vysledek : {prod}")
|
||||
```
|
@ -1,25 +0,0 @@
|
||||
# fizzbuzz.py
|
||||
```python
|
||||
|
||||
# tahame hodnotu od uzivatele
|
||||
lim = int(input('zadej cislo : '))
|
||||
|
||||
# prazny string
|
||||
output = ''
|
||||
# vsechna cisla do lim
|
||||
for i in range(lim):
|
||||
# reset promenny output
|
||||
output = ''
|
||||
|
||||
# pokud delitelne tremi
|
||||
if i % 3 == 0:
|
||||
output += 'fizz'
|
||||
# pokud delitelne peti
|
||||
if i % 5 == 0:
|
||||
output += 'buzz'
|
||||
|
||||
# zjistujeme jestli nam to
|
||||
# stoji za to vypsat
|
||||
if output != '':
|
||||
print(output)
|
||||
```
|
@ -1,15 +0,0 @@
|
||||
# bigdick_sito.py
|
||||
```python
|
||||
# Tak tady bude nejaka cool implementace erastotenova sita
|
||||
# timhle se radsi zatim netrapte
|
||||
from functools import reduce
|
||||
def gen_primes(lim): # kratsi nazev -> optimalizace :D
|
||||
return [i for i in reduce((lambda a, b : [(i[0] if i[0]==i[1] else 0) for i in zip(a,b)]),[[(0 if ((x % i == 0) and (x != i)) else x) for x in range(2, lim)] for i in range(2, lim)]) if i != 0] # hehe :D
|
||||
# lol tohle je doslova nenormalni
|
||||
# prosim nepiste takovyhle kod, nikdo tomu nebude rozumet
|
||||
# ale je to celkem flex
|
||||
|
||||
print(gen_primes(int(input("zadej cislo : "))))
|
||||
|
||||
# je to dost pomalejsi nez to predtim ale je to rozhodne vic cool
|
||||
```
|
@ -1,53 +0,0 @@
|
||||
# erastotenovo_sito.py
|
||||
```python
|
||||
# yeehaw
|
||||
# budeme hledat prvocisla
|
||||
# fakt super
|
||||
# zacnu od udelani funkce ktera bere
|
||||
# horni hranici intervalu a vrati mi seznam
|
||||
# vsech prvocisel do tyto hranice
|
||||
|
||||
# generate_primes(10) ma vyhodit [2, 3, 5, 7]
|
||||
def generate_primes(lim): # lim je horni hranice intervalu
|
||||
nums = list(range(2, lim)) # seznam vsech cisel od 2 do lim
|
||||
primes = [] # prazny seznam
|
||||
|
||||
x = nums[0] # ulozime si prvni cislo
|
||||
# ktery je prvocislo
|
||||
while x < int(lim**0.5): # staci ze hledam do odmocniny z lim
|
||||
# teoreticky bych mohl napsat jenom
|
||||
# while nums[0] < lim
|
||||
# ale je to pomalejsi
|
||||
# jo a int() mi z toho udela cele cislo
|
||||
# coz odmocnina neni
|
||||
x = nums[0] # aktualizace x, ma smysl az po prvnim cyklu
|
||||
# prvocislo
|
||||
|
||||
temp = [] # temporary seznam do kteryho budeme kopirovat
|
||||
|
||||
primes.append(x) # ukladame prvocislo do seznamu prvocisel
|
||||
|
||||
for i in nums: # prochazime nums a snazime se filtrovat
|
||||
# cili nechat jenom cisla ktery nejsou delitelna nove pridanym
|
||||
# prvocislem
|
||||
if i % x: # True jenom pokud `i % x` neni 0 -> nedelitelny
|
||||
temp.append(i) # temp nam slouzi jako budouci nums
|
||||
|
||||
nums = temp # pozirame temp a aktualizujeme nums
|
||||
|
||||
primes += nums # jinak by mi chybely cisla protoze jsem nahore
|
||||
# napsal :
|
||||
# while x< int(lim**0.5)
|
||||
# kdybych to tam nenapsal tak tohle muzu vynechat
|
||||
|
||||
return primes # vracim cisla
|
||||
|
||||
print(generate_primes(int(input("zadej cislo : "))))
|
||||
# tohle je mozna trochu prasacky
|
||||
# mohl jsem to rozepsat jako :
|
||||
|
||||
# i = int(input("zadej cislo : "))
|
||||
# print(generate_primes(i))
|
||||
|
||||
# ale nechtelo se mi lol
|
||||
```
|
@ -1,9 +0,0 @@
|
||||
# nejbigdick.py
|
||||
```python
|
||||
# tady te mam docente
|
||||
def gp(n):
|
||||
return [n[0]] + gp([i for i in n[1:] if i%n[0] != 0]) if n else [] # mnohem rychlejsi
|
||||
|
||||
print(gp(range(2, int(input('zadej cislo : ')))))
|
||||
# touche
|
||||
```
|
@ -1,13 +0,0 @@
|
||||
# vic_bigdick_sito.py
|
||||
```python
|
||||
# Sire Kubisi, tady jsem vas dobehl
|
||||
# Tohle single line sito je lepsi, kratsi a rychlejsi
|
||||
# (Meril jsem to pomoci timeit)
|
||||
|
||||
from functools import reduce
|
||||
|
||||
def primes(n):
|
||||
return reduce(lambda l, x: [y for y in l if y==x or y%x!=0], range(2, n), range(2, n))
|
||||
|
||||
print(primes(int(input("Zadej cislo: "))))
|
||||
```
|
@ -1,23 +0,0 @@
|
||||
# faktorial_rekurze.py
|
||||
```python
|
||||
# tady budeme resit faktorial rekurzivne
|
||||
# matematicka definice :
|
||||
#f(0) = 1
|
||||
#f(n) = n * f(n - 1)
|
||||
# takze vidime rekurzi - muzeme vyuzit
|
||||
|
||||
def f(n):
|
||||
if n == 0: # f(0) = 1
|
||||
return 1
|
||||
# tady nepotrebujeme else, jelikoz v predchozim
|
||||
# if-u je return
|
||||
return n * f(n - 1) # f(n) = n * f(n - 1)
|
||||
|
||||
print(f(3)) # f(3) = 6
|
||||
# f(3) = 3 * f(2) = 3 * 2 * f(1) = 3 * 2 * 1 * f(0) = 3 * 2 * 1 * 1 = 6
|
||||
|
||||
print(f(100)) # je to celkem v pohode, az na to ze python neni uplne
|
||||
# dobrej pokud jde o rekurzi
|
||||
# zkuste treba co se stane kdyz udelate :
|
||||
#print(f(1000))
|
||||
```
|
@ -1,3 +0,0 @@
|
||||
# fibonacci.py
|
||||
```python
|
||||
```
|
@ -1,9 +0,0 @@
|
||||
# fibonacci_rekurze.py
|
||||
```python
|
||||
# tahle vypada fibonacciho posloupnost :
|
||||
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... # atd
|
||||
# zacneme matematickou definici :
|
||||
#f(0) = 0
|
||||
#f(1) = 1
|
||||
|
||||
```
|
@ -1,9 +0,0 @@
|
||||
# priklad.py
|
||||
```python
|
||||
|
||||
|
||||
class Clovek:
|
||||
def __init__(self, age, weight):
|
||||
self.age = age
|
||||
self.weight = weight
|
||||
```
|
@ -1,74 +0,0 @@
|
||||
# fraction.py
|
||||
```python
|
||||
#!/usr/bin/python
|
||||
|
||||
from math import gcd # importuju greatest common divisor
|
||||
# aby se mi snaz kratily zlomky
|
||||
|
||||
# definujeme novou tridu
|
||||
class Fraction:
|
||||
|
||||
# definujeme co se ma dit pri vytvoreni objektu
|
||||
def __init__(self, up, down):
|
||||
self.up = up # self.up != up
|
||||
self.down = down
|
||||
self.base() # bude se hodit pri zbytku implementaci
|
||||
# zarucuje ze nebudeme muset explicitne volat
|
||||
# metodu `base` nikde jinde
|
||||
|
||||
# kraceni zlomku
|
||||
# vsimneme si ze narozdil od funkci, u metod
|
||||
# je v pohode i jiny typ vraceni z funkce nez
|
||||
# jenom pomoci `return`
|
||||
# - metoda muze menit objekt kterymu nalezi
|
||||
def base(self):
|
||||
divisor = gcd(self.up, self.down) # ziskavame nejvedsi spolecny delitel
|
||||
if divisor > 1: # zjistujeme jestli muzeme kratit
|
||||
self.up = self.up // divisor # znena sebe sama
|
||||
self.down = self.down // divisor # a zase
|
||||
|
||||
if self.up < 0 and self.down < 0:
|
||||
self.up = -self.up
|
||||
self.down = -self.down
|
||||
|
||||
|
||||
# scitani zlomku
|
||||
def add(self, other):
|
||||
return Fraction(self.up * other.down + other.up * self.down, self.down * other.down)
|
||||
# ^- tohle mi zaruci ze se ten zlomek automaticky zkrati
|
||||
# jelikoz tvorim novy objekt a v initu mam `self.base()`
|
||||
# taky vracim jiny objekt a nemenim ty, ktere jsem dostal
|
||||
|
||||
# nasobeni zlomku
|
||||
def multiply(self, other):
|
||||
return Fraction(self.up * other.up, self.down * other.down)
|
||||
|
||||
# odcitani zlomku
|
||||
def subtract(self, other):
|
||||
return Fraction(self.up * other.down - other.up * self.down, self.down * other.down)
|
||||
|
||||
# deleni
|
||||
# prosim tady nepouzivat pythonovsky deleni, je velice nepresny
|
||||
def divide(self, other):
|
||||
return Fraction(self.up * other.down, self.down * other.up)
|
||||
|
||||
# aby se mi to hezky printlo
|
||||
def show(self):
|
||||
return f"{self.up}/{self.down}"
|
||||
|
||||
# testy
|
||||
|
||||
for x in range(1, 4):
|
||||
for y in range(1, 4):
|
||||
a = Fraction(x, y)
|
||||
b = Fraction(y, x)
|
||||
|
||||
print(f"\na: {a.show()}\nb: {b.show()}\n")
|
||||
|
||||
print("+", a.add(b).show())
|
||||
print("*", a.multiply(b).show())
|
||||
print("-", a.subtract(b).show())
|
||||
print("/", a.divide(b).show())
|
||||
|
||||
# ez
|
||||
```
|
@ -1,9 +0,0 @@
|
||||
# animal.py
|
||||
```python
|
||||
|
||||
class Animal:
|
||||
|
||||
class Bird:
|
||||
|
||||
class Mammal:
|
||||
```
|
@ -1,11 +0,0 @@
|
||||
|
||||
all: code site
|
||||
|
||||
|
||||
site:
|
||||
python3 site_gen.py
|
||||
|
||||
code:
|
||||
python3 code_gen.py
|
||||
|
||||
.PHONY: site code
|
@ -1,4 +0,0 @@
|
||||
# python-gjk
|
||||
|
||||
Učí profesor Kubis a docent Veškrna.
|
||||
|
@ -1,88 +1 @@
|
||||
# python-gjk
|
||||
|
||||
Učí profesor Kubis a docent Veškrna.
|
||||
|
||||
## 01
|
||||
+ [bool_vyrazy](01/bool_vyrazy)
|
||||
+ [datove_typy](01/datove_typy)
|
||||
+ [if](01/if)
|
||||
+ [interpretace](01/interpretace)
|
||||
+ [komentare](01/komentare)
|
||||
+ [kricici_lukas](01/kricici_lukas)
|
||||
+ [operace](01/operace)
|
||||
+ [promenne](01/promenne)
|
||||
+ [python_interpreter](01/python_interpreter)
|
||||
+ [sude_nebo_liche](01/sude_nebo_liche)
|
||||
+ [zakladni_funkce](01/zakladni_funkce)
|
||||
|
||||
## 02
|
||||
+ [umocnovani](02/umocnovani)
|
||||
+ [while](02/while)
|
||||
|
||||
## 03
|
||||
+ [fizzbuzz](03/fizzbuzz)
|
||||
+ [for](03/for)
|
||||
+ [funkce](03/funkce)
|
||||
+ [range](03/range)
|
||||
+ [seznam](03/seznam)
|
||||
|
||||
## 04
|
||||
+ [bigdick_sito](04/bigdick_sito)
|
||||
+ [erastotenovo_sito](04/erastotenovo_sito)
|
||||
+ [nejbigdick](04/nejbigdick)
|
||||
+ [vic_bigdick_sito](04/vic_bigdick_sito)
|
||||
|
||||
## [05](05)
|
||||
|
||||
## [06](06)
|
||||
|
||||
## [07](07)
|
||||
|
||||
## 08
|
||||
+ [dict](08/dict)
|
||||
+ [importy](08/importy)
|
||||
+ [list_comprehensions](08/list_comprehensions)
|
||||
+ [requests_and_http](08/requests_and_http)
|
||||
+ [tenary_operator](08/tenary_operator)
|
||||
|
||||
## [09](09)
|
||||
|
||||
## [10](10)
|
||||
|
||||
## 11
|
||||
+ [faktorial_rekurze](11/faktorial_rekurze)
|
||||
+ [fibonacci](11/fibonacci)
|
||||
+ [fibonacci_rekurze](11/fibonacci_rekurze)
|
||||
+ [rekurze](11/rekurze)
|
||||
|
||||
## 12
|
||||
+ [priklad](12/priklad)
|
||||
+ [tridy_a_objekty](12/tridy_a_objekty)
|
||||
|
||||
## 13
|
||||
+ [fraction](13/fraction)
|
||||
|
||||
## 14
|
||||
+ [animal](14/animal)
|
||||
+ [dedicnost](14/dedicnost)
|
||||
|
||||
##
|
||||
+ [code_gen](code_gen)
|
||||
+ [site_gen](site_gen)
|
||||
|
||||
## fotky
|
||||
+ [kubis1](fotky/kubis1)
|
||||
+ [kubis2](fotky/kubis2)
|
||||
|
||||
## projekty/star_wars
|
||||
+ [matej](projekty/star_wars/matej)
|
||||
+ [petr](projekty/star_wars/petr)
|
||||
|
||||
## projekty/tic_tac_toe
|
||||
+ [katka](projekty/tic_tac_toe/katka)
|
||||
+ [matej](projekty/tic_tac_toe/matej)
|
||||
+ [ondra](projekty/tic_tac_toe/ondra)
|
||||
+ [petr](projekty/tic_tac_toe/petr)
|
||||
+ [tobias](projekty/tic_tac_toe/tobias)
|
||||
+ [vlasta](projekty/tic_tac_toe/vlasta)
|
||||
|
||||
# Python
|
||||
|
@ -1,23 +0,0 @@
|
||||
# code_gen.py
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
from site_gen import get_ext
|
||||
import os
|
||||
|
||||
def mkformat(name, lines):
|
||||
result = []
|
||||
result.append(f'# {name}\n')
|
||||
result.append('```python\n')
|
||||
result += lines
|
||||
result.append('```')
|
||||
return result
|
||||
|
||||
if __name__=='__main__':
|
||||
files = [(i + '.py', i + '.md') for i in get_ext('.', '.py')]
|
||||
|
||||
for py, md in files:
|
||||
with open(py) as p:
|
||||
with open(md, 'w') as m:
|
||||
m.writelines(mkformat(os.path.split(p.name)[1], p.readlines()))
|
||||
```
|
@ -1,20 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from site_gen import get_ext
|
||||
import os
|
||||
|
||||
def mkformat(name, lines):
|
||||
result = []
|
||||
result.append(f'# {name}\n')
|
||||
result.append('```python\n')
|
||||
result += lines
|
||||
result.append('```')
|
||||
return result
|
||||
|
||||
if __name__=='__main__':
|
||||
files = [(i + '.py', i + '.md') for i in get_ext('.', '.py')]
|
||||
|
||||
for py, md in files:
|
||||
with open(py) as p:
|
||||
with open(md, 'w') as m:
|
||||
m.writelines(mkformat(os.path.split(p.name)[1], p.readlines()))
|
@ -1 +0,0 @@
|
||||
![kubis1](kubis1.jpg)
|
@ -1 +0,0 @@
|
||||
![kubis2](kubis2.jpg)
|
@ -1,59 +0,0 @@
|
||||
# site_gen.py
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
from functools import reduce
|
||||
|
||||
def get_ext(path, ext):
|
||||
results = []
|
||||
for i in os.listdir(path):
|
||||
if i[0] == '.':
|
||||
continue
|
||||
if os.path.isdir(os.path.join(path, i)):
|
||||
results = results + get_ext(os.path.join(path, i), ext)
|
||||
else:
|
||||
name, extension = os.path.splitext(i)
|
||||
if extension == ext:
|
||||
results.append(os.path.join(path, name))
|
||||
return results
|
||||
|
||||
def mkformat(files):
|
||||
result = []
|
||||
files = [list(os.path.split(i)) for i in files]
|
||||
files = path_dict(files)
|
||||
|
||||
for key in files:
|
||||
if 'README' in files[key]:
|
||||
result.append(f'## [{key}]({key})')
|
||||
else:
|
||||
result.append(f'## {key}')
|
||||
for name in [i for i in sorted(files[key]) if i != 'README']:
|
||||
result.append(f'+ [{name}]({os.path.join(key, name)})')
|
||||
result.append('')
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def path_dict(files):
|
||||
di = dict()
|
||||
for x, y in files:
|
||||
if not di.get(x):
|
||||
di[x] = []
|
||||
di[x].append(y)
|
||||
return di
|
||||
|
||||
if __name__=='__main__':
|
||||
prefix = []
|
||||
if os.path.exists('PREFIX.md'):
|
||||
with open('PREFIX.md') as p:
|
||||
prefix = p.readlines()
|
||||
|
||||
files = sorted([i[2:] for i in get_ext('.', '.md') if i != './README' and i != './PREFIX'])
|
||||
|
||||
with open('README.md', 'w') as f:
|
||||
to_write = mkformat(files)
|
||||
to_write = [i + '\n' for i in to_write]
|
||||
to_write = prefix + to_write
|
||||
f.writelines(to_write)
|
||||
```
|
@ -1,56 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
from functools import reduce
|
||||
|
||||
def get_ext(path, ext):
|
||||
results = []
|
||||
for i in os.listdir(path):
|
||||
if i[0] == '.':
|
||||
continue
|
||||
if os.path.isdir(os.path.join(path, i)):
|
||||
results = results + get_ext(os.path.join(path, i), ext)
|
||||
else:
|
||||
name, extension = os.path.splitext(i)
|
||||
if extension == ext:
|
||||
results.append(os.path.join(path, name))
|
||||
return results
|
||||
|
||||
def mkformat(files):
|
||||
result = []
|
||||
files = [list(os.path.split(i)) for i in files]
|
||||
files = path_dict(files)
|
||||
|
||||
for key in files:
|
||||
if 'README' in files[key]:
|
||||
result.append(f'## [{key}]({key})')
|
||||
else:
|
||||
result.append(f'## {key}')
|
||||
for name in [i for i in sorted(files[key]) if i != 'README']:
|
||||
result.append(f'+ [{name}]({os.path.join(key, name)})')
|
||||
result.append('')
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def path_dict(files):
|
||||
di = dict()
|
||||
for x, y in files:
|
||||
if not di.get(x):
|
||||
di[x] = []
|
||||
di[x].append(y)
|
||||
return di
|
||||
|
||||
if __name__=='__main__':
|
||||
prefix = []
|
||||
if os.path.exists('PREFIX.md'):
|
||||
with open('PREFIX.md') as p:
|
||||
prefix = p.readlines()
|
||||
|
||||
files = sorted([i[2:] for i in get_ext('.', '.md') if i != './README' and i != './PREFIX'])
|
||||
|
||||
with open('README.md', 'w') as f:
|
||||
to_write = mkformat(files)
|
||||
to_write = [i + '\n' for i in to_write]
|
||||
to_write = prefix + to_write
|
||||
f.writelines(to_write)
|
Loading…
Reference in New Issue