Commit 47d75288 authored by cermak's avatar cermak
Browse files

Lesson 8 solution

parent 528a33c1
Pipeline #21413 passed with stage
in 1 minute and 38 seconds
def mujrange(n):
i = 0
while i < n:
yield i
i += 1
def kartezsky_soucin(l1, l2):
for x in l1:
for y in l2:
yield (x, y)
from collections import defaultdict
def kgramy(text, k):
stat=defaultdict(int)
for i in range(len(text)-k+1):
stat[text[i:i+k]] += 1
return stat
\ No newline at end of file
...@@ -3,32 +3,27 @@ ...@@ -3,32 +3,27 @@
x, y = 0, 0 x, y = 0, 0
dx, dy = 1, 0 dx, dy = 1, 0
def prikaz_krok(): def fKROK():
global x, y, dx, dy global x,y,dx,dy
x += dx x += dx
y += dy y += dy
def prikaz_vlevo(): def fVLEVO():
global dx, dy global dx, dy
dx, dy = -dy, dx dx, dy = -dy, dx
def prikaz_vpravo(): commands = {
global dx, dy "KROK": fKROK,
dx, dy = dy, -dx "VLEVO": fVLEVO
prikazy = {
"krok": prikaz_krok,
"vlevo": prikaz_vlevo,
"vpravo": prikaz_vpravo,
} }
def proved(prikaz):
if prikaz in prikazy:
prikazy[prikaz]()
else:
print("Neznámý příkaz!")
while True: while True:
print(f"Pozice: ({x},{y}), směr: ({dx},{dy})") prikaz = input("Zadej příkaz:")
prikaz = input("Příkaz: ") if not prikaz:
proved(prikaz) break
if prikaz in commands:
commands[prikaz]()
else:
print("Nerozumím")
print(f"Karel je na {x=} a {y=}, kouká se směrem ({dx},{dy})")
print("KONEC")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment